// TestShutdown ensures Shutdown causes Run() to exit cleanly.
TestShutdown ensures Shutdown causes Run() to exit cleanly.
// TestShutdown ensures Shutdown causes Run () to exit cleanly .
func TestShutdown(t *testing.T) {
	t.Parallel()
	hf := SimpleHandler(func(_ Task, c <-chan bool) bool {
		<-c
		return false
	})
	coord := NewTestCoord()
	c, _ := NewConsumer(coord, hf, DumbBalancer)
	go c.Run()
	coord.Tasks <- testTask{"1"}
	coord.Tasks <- testTask{"2"}
	coord.Tasks <- testTask{"3"}
	time.Sleep(100 * time.Millisecond)
	if len(coord.Dones)+len(coord.Releases) > 0 {
		t.Fatalf("Didn't expect any tasks to exit before Shutdown was called.")
	}
	c.Shutdown()
	for i := 3; i > 0; i-- {
		select {
		case task := <-coord.Dones:
			t.Errorf("%s makred done when it should have been Released!", task)
		case task := <-coord.Releases:
			t.Logf("%s relased", task)
		case <-time.After(200 * time.Millisecond):
			t.Fatalf("Took too long to mark task(s) as released.")
		}
	}
}
func TestShutdown ( t * testing . T ) { t . Parallel ( ) hf := SimpleHandler ( func ( _ Task , c <- chan bool ) bool { <- c return false } ) coord := NewTestCoord ( ) c , _ := NewConsumer ( coord , hf , DumbBalancer ) go c . Run ( ) coord . Tasks <- testTask { " " } coord . Tasks <- testTask { " " } coord . Tasks <- testTask { " " } time . Sleep ( 100 * time . Millisecond ) if len ( coord . Dones ) + len ( coord . Releases ) > 0 { t . Fatalf ( " " ) } c . Shutdown ( ) for i := 3 ; i > 0 ; i -- { select { case task := <- coord . Dones : t . Errorf ( " " , task ) case task := <- coord . Releases : t . Logf ( " " , task ) case <- time . After ( 200 * time . Millisecond ) : t . Fatalf ( " " ) } } }
TestShutdown ensures Shutdown causes Run() to exit cleanly.
TestShutdown ensures Shutdown causes Run () to exit cleanly .