fix nextlocalid sort bug

This commit is contained in:
Erik Winter 2021-07-25 10:02:18 +02:00
parent 4f80808531
commit 1c25c8182c
3 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package storage
import ( import (
"errors" "errors"
"sort"
"time" "time"
"git.ewintr.nl/gte/internal/task" "git.ewintr.nl/gte/internal/task"
@ -26,6 +27,7 @@ func NextLocalId(used []int) int {
return 1 return 1
} }
sort.Ints(used)
usedMax := 1 usedMax := 1
for _, u := range used { for _, u := range used {
if u > usedMax { if u > usedMax {

View File

@ -58,6 +58,14 @@ func TestNextLocalId(t *testing.T) {
used: []int{99}, used: []int{99},
exp: 1, 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) { t.Run(tc.name, func(t *testing.T) {
test.Equals(t, tc.exp, storage.NextLocalId(tc.used)) test.Equals(t, tc.exp, storage.NextLocalId(tc.used))

View File

@ -120,6 +120,7 @@ VALUES
used = append(used, localId) used = append(used, localId)
} }
} }
for id, localId := range localIdMap { for id, localId := range localIdMap {
if localId == 0 { if localId == 0 {
newLocalId := NextLocalId(used) newLocalId := NextLocalId(used)