Fix data race in datanode tests

Signed-off-by: sunby <bingyi.sun@zilliz.com>
pull/4973/head^2
sunby 2021-03-24 16:35:38 +08:00 committed by yefu.chen
parent 972dad4d8e
commit ca3187d173
2 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"math/rand"
"os"
"strconv"
"sync"
"testing"
"time"
@ -384,6 +385,7 @@ func (df *DataFactory) GetMsgStreamInsertMsgs(n int) (inMsgs []*msgstream.Insert
}
type AllocatorFactory struct {
sync.Mutex
r *rand.Rand
}
@ -395,7 +397,9 @@ func NewAllocatorFactory(id ...UniqueID) *AllocatorFactory {
return f
}
func (alloc AllocatorFactory) allocID() (UniqueID, error) {
func (alloc *AllocatorFactory) allocID() (UniqueID, error) {
alloc.Lock()
defer alloc.Unlock()
return alloc.r.Int63n(1000000), nil
}

View File

@ -45,7 +45,7 @@ func TestDataSyncService_Start(t *testing.T) {
"receiveBufSize": 1024,
"pulsarBufSize": 1024}
err := msFactory.SetParams(m)
sync := newDataSyncService(ctx, flushChan, replica, allocFactory, msFactory)
sync := newDataSyncService(ctx, flushChan, replica, &allocFactory, msFactory)
sync.replica.addCollection(collMeta.ID, collMeta.Schema)
sync.init()
go sync.start()