github.com/metaworking/channeld@v0.7.3/pkg/channeld/channel_test.go (about) 1 package channeld 2 3 import ( 4 "log" 5 "sync" 6 "testing" 7 "time" 8 9 "github.com/metaworking/channeld/pkg/channeldpb" 10 "github.com/metaworking/channeld/pkg/common" 11 ) 12 13 func TestConcurrentAccessChannels(t *testing.T) { 14 InitLogs() 15 InitChannels() 16 wg := sync.WaitGroup{} 17 18 wg.Add(1) 19 go func() { 20 for i := 0; i < 100; i++ { 21 CreateChannel(channeldpb.ChannelType_SUBWORLD, nil) 22 time.Sleep(1 * time.Millisecond) 23 } 24 wg.Done() 25 }() 26 27 // Read-Write ratio = 100:1 28 for i := 0; i < 100; i++ { 29 wg.Add(1) 30 go func() { 31 counter := 0 32 for i := 0; i < 100; i++ { 33 if GetChannel(common.ChannelId(i)) != nil { 34 counter++ 35 } 36 time.Sleep(1 * time.Millisecond) 37 } 38 log.Println(counter) 39 wg.Done() 40 }() 41 } 42 43 wg.Add(1) 44 go func() { 45 for i := 0; i < 100; i++ { 46 allChannels.Range(func(k common.ChannelId, v *Channel) bool { 47 return true 48 }) 49 time.Sleep(1 * time.Millisecond) 50 } 51 wg.Done() 52 }() 53 54 wg.Wait() 55 }