v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/broadcast/butil/broadcastchannel_test.go (about) 1 package butil 2 3 import ( 4 "testing" 5 ) 6 7 func TestBroadcastChannel(t *testing.T) { 8 bc := BroadcastChannel("Hello, World!") 9 defer bc.Close() 10 11 var ctr uint32 12 bc.OnMessage = func(v interface{}) { 13 ctr += v.(uint32) 14 } 15 for i := 0; i < 100; i++ { 16 bc.PostMessage(uint32(100)) 17 } 18 if ctr != 10000 { 19 t.Errorf("ctr == %d, want 10000", ctr) 20 } 21 }