forked from longtao.wu/droboticflow
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package store
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestProjectDictionariesPreserveIndependentSelections(t *testing.T) {
|
|
s := NewMemoryStore()
|
|
ctx := t.Context()
|
|
var wg sync.WaitGroup
|
|
for i := 0; i < 20; i++ {
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
_ = s.UpsertProjectAnnotationLabels(ctx, domain.ProjectAnnotationLabelsRecord{ID: "selection", ProjectID: "p", LabelIDs: []string{"action"}})
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
_ = s.UpsertProjectSliceLabels(ctx, domain.ProjectAnnotationLabelsRecord{ID: "selection", ProjectID: "p", SliceLabelIDs: []string{"slice"}})
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
got, err := s.GetProjectAnnotationLabels(ctx, "p")
|
|
if err != nil || len(got.LabelIDs) != 1 || len(got.SliceLabelIDs) != 1 {
|
|
t.Fatalf("%+v %v", got, err)
|
|
}
|
|
raw, _ := bson.Marshal(domain.ProjectAnnotationLabelsRecord{ProjectID: "p", LabelIDs: []string{}})
|
|
var patch bson.M
|
|
_ = bson.Unmarshal(raw, &patch)
|
|
if _, ok := patch["sliceLabelIds"]; ok {
|
|
t.Fatal("legacy Mongo $set would clear slice selection")
|
|
}
|
|
}
|