Skip to content

Commit

Permalink
TestHardTimeoutCancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Brophy committed Dec 3, 2017
1 parent 76189ad commit 2acdb38
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions blaster/blaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,35 @@ func TestHardTimeout(t *testing.T) {

}

func TestHardTimeoutCancel(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
b := New(ctx, cancel)
b.Rate = 0 // set rate to 0 so we can inject items synthetically
b.softTimeout = 10 * time.Millisecond
b.hardTimeout = 20 * time.Millisecond

worker := new(LoggingWorker)
b.SetWorker(worker.NewHangForever)

finished := make(chan error, 1)
go func() {
finished <- b.start(ctx)
}()

// synthetically call the main channel, which is what the ticker would do
b.mainChannel <- 0

b.Exit()

// wait for the start method to finish
err := <-finished
if err.Error() != "a worker was still sending after timeout + 1 second. This indicates a bug in the worker code. Workers should immediately exit on receiving a signal from ctx.Done()" {
t.Fatal("Unexpected error:", err)
}

}

func TestCancel(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 2acdb38

Please sign in to comment.