MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestConcurrentGetSet

Function TestConcurrentGetSet

consistent/consistent_test.go:971–1011  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

969}
970
971func TestConcurrentGetSet(t *testing.T) {
972 kms.Unittest = true
973 utils.RemoveAll(testStorePath + "*")
974 kms.ResetBucket()
975
976 x, _ := InitConsistent(testStorePath, new(KMSStorage), false)
977 defer utils.RemoveAll(testStorePath + "*")
978 x.Set([]Node{NewNodeFromString("0000"), NewNodeFromString("1111"), NewNodeFromString("2222"), NewNodeFromString("3333"), NewNodeFromString("4444")})
979
980 var wg sync.WaitGroup
981 for i := 0; i < 10; i++ {
982 wg.Add(1)
983 go func() {
984 for i := 0; i < 100; i++ {
985 x.Set([]Node{NewNodeFromString("0000"), NewNodeFromString("1111"), NewNodeFromString("2222"), NewNodeFromString("3333"), NewNodeFromString("4444")})
986 time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond)
987 x.Set([]Node{NewNodeFromString("5555"), NewNodeFromString("6666"), NewNodeFromString("7777")})
988 time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond)
989 }
990 wg.Done()
991 }()
992 }
993
994 for i := 0; i < 100; i++ {
995 wg.Add(1)
996 go func() {
997 for i := 0; i < 100; i++ {
998 a, err := x.GetNeighbor("111111")
999 if err != nil {
1000 t.Error(err)
1001 }
1002 if a.ID != "5555" && a.ID != "3333" {
1003 t.Errorf("got %v, expected 5555 or 3333", a)
1004 }
1005 time.Sleep(time.Duration(rand.Intn(10)) * time.Millisecond)
1006 }
1007 wg.Done()
1008 }()
1009 }
1010 wg.Wait()
1011}

Callers

nothing calls this directly

Calls 10

RemoveAllFunction · 0.92
ResetBucketFunction · 0.92
InitConsistentFunction · 0.85
NewNodeFromStringFunction · 0.85
GetNeighborMethod · 0.80
ErrorMethod · 0.80
ErrorfMethod · 0.80
WaitMethod · 0.80
SetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected