@@ -18,6 +18,34 @@ func TestWorkerPoolSubmitAfterStop(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkerPoolRecoversTaskPanicAndContinues(t *testing.T) {
|
||||
pool := newWorkerPool(1, 2)
|
||||
pool.start()
|
||||
defer pool.stop()
|
||||
|
||||
panicked, err := pool.submit(context.Background(), func(context.Context) (any, error) {
|
||||
panic("boom")
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("submit panic task returned error: %v", err)
|
||||
}
|
||||
result := <-panicked
|
||||
if !errors.Is(result.err, ErrPoolWorkerPanic) {
|
||||
t.Fatalf("expected ErrPoolWorkerPanic, got %v", result.err)
|
||||
}
|
||||
|
||||
continued, err := pool.submit(context.Background(), func(context.Context) (any, error) {
|
||||
return "ok", nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("submit follow-up returned error: %v", err)
|
||||
}
|
||||
result = <-continued
|
||||
if result.err != nil || result.value != "ok" {
|
||||
t.Fatalf("worker did not continue: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkerPoolQueueFull(t *testing.T) {
|
||||
pool := newWorkerPool(1, 1)
|
||||
pool.start()
|
||||
|
||||
Reference in New Issue
Block a user