package swarm import ( "context" "fmt" "testing" "time" ) func testwork(req string) error { fmt.Println(req) return nil } func Test_swarm(t *testing.T) { swarm := NewSwarm(10, testwork) for range 10 { go func() { for { swarm.scheduler.Submit("nihao") time.Sleep(time.Second) } }() } ctx, calFn := context.WithTimeout(context.Background(), 5*time.Second) defer calFn() swarm.Run(ctx) }