test concurrent value imports, fix race

This commit is contained in:
Matt Jaffee 2019-03-25 14:03:10 -05:00
parent 9fda9cf6a3
commit 4420d72196
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 23 additions and 0 deletions

View file

@ -1785,7 +1785,9 @@ func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear
for i := uint(0); i < bitDepth+1; i++ {
rowSet[uint64(i)] = struct{}{}
}
f.mu.Lock()
err := f.importPositions(toSet, toClear, rowSet)
f.mu.Unlock()
return errors.Wrap(err, "importing positions")
}
err := f.snapshot()

View file

@ -3024,3 +3024,24 @@ func TestSmallImportRestart(t *testing.T) {
t.Errorf("row 1 should be [1], but got %v", r1)
}
}
func TestImportValueConcurrent(t *testing.T) {
f := mustOpenFragment("i", "f", viewBSIGroupPrefix+"foo", 0, "none")
eg := &errgroup.Group{}
for i := 0; i < 4; i++ {
i := i
eg.Go(func() error {
for j := uint64(0); j < 10; j++ {
err := f.importValue([]uint64{j}, []uint64{uint64(rand.Int63n(1000))}, 10, i%2 == 0)
if err != nil {
return err
}
}
return nil
})
}
err := eg.Wait()
if err != nil {
t.Fatalf("concurrently importing values: %v", err)
}
}