fix nextlocalid sort bug
This commit is contained in:
parent
4f80808531
commit
1c25c8182c
|
@ -2,6 +2,7 @@ package storage
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.ewintr.nl/gte/internal/task"
|
||||
|
@ -26,6 +27,7 @@ func NextLocalId(used []int) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
sort.Ints(used)
|
||||
usedMax := 1
|
||||
for _, u := range used {
|
||||
if u > usedMax {
|
||||
|
|
|
@ -58,6 +58,14 @@ func TestNextLocalId(t *testing.T) {
|
|||
used: []int{99},
|
||||
exp: 1,
|
||||
},
|
||||
{
|
||||
name: "sync bug",
|
||||
used: []int{151, 956, 955, 150, 154, 155, 145, 144,
|
||||
136, 152, 148, 146, 934, 149, 937, 135, 140, 139,
|
||||
143, 137, 153, 939, 138, 953, 147, 141, 938, 142,
|
||||
},
|
||||
exp: 957,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
test.Equals(t, tc.exp, storage.NextLocalId(tc.used))
|
||||
|
|
|
@ -120,6 +120,7 @@ VALUES
|
|||
used = append(used, localId)
|
||||
}
|
||||
}
|
||||
|
||||
for id, localId := range localIdMap {
|
||||
if localId == 0 {
|
||||
newLocalId := NextLocalId(used)
|
||||
|
|
Loading…
Reference in New Issue