github.com/lingyao2333/mo-zero@v1.4.1/core/threading/workergroup_test.go (about) 1 package threading 2 3 import ( 4 "fmt" 5 "runtime" 6 "sync" 7 "testing" 8 9 "github.com/lingyao2333/mo-zero/core/lang" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestWorkerGroup(t *testing.T) { 14 m := make(map[string]lang.PlaceholderType) 15 var lock sync.Mutex 16 var wg sync.WaitGroup 17 wg.Add(runtime.NumCPU()) 18 group := NewWorkerGroup(func() { 19 lock.Lock() 20 m[fmt.Sprint(RoutineId())] = lang.Placeholder 21 lock.Unlock() 22 wg.Done() 23 }, runtime.NumCPU()) 24 go group.Start() 25 wg.Wait() 26 assert.Equal(t, runtime.NumCPU(), len(m)) 27 }