Skip to content

Commit

Permalink
tests: use errors.Is() to check for specific errors
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Hahling <[email protected]>
  • Loading branch information
rolinh authored and tklauser committed Sep 14, 2021
1 parent 93ef05b commit f3aa07d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions workerpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package workerpool_test

import (
"context"
"errors"
"fmt"
"runtime"
"sync"
Expand Down Expand Up @@ -285,12 +286,12 @@ func TestConcurrentDrain(t *testing.T) {
<-ready
time.Sleep(10 * time.Millisecond)

if err := wp.Submit("", nil); err != workerpool.ErrDraining {
if err := wp.Submit("", nil); !errors.Is(err, workerpool.ErrDraining) {
t.Errorf("submit: got '%v', want '%v'", err, workerpool.ErrDraining)
}

results, err := wp.Drain()
if err != workerpool.ErrDraining {
if !errors.Is(err, workerpool.ErrDraining) {
t.Errorf("drain: got '%v', want '%v'", err, workerpool.ErrDraining)
}
if results != nil {
Expand Down Expand Up @@ -321,7 +322,7 @@ func TestWorkerPoolDrainAfterClose(t *testing.T) {
wp := workerpool.New(runtime.NumCPU())
wp.Close()
tasks, err := wp.Drain()
if err != workerpool.ErrClosed {
if !errors.Is(err, workerpool.ErrClosed) {
t.Errorf("got %v; want %v", err, workerpool.ErrClosed)
}
if tasks != nil {
Expand All @@ -332,7 +333,7 @@ func TestWorkerPoolDrainAfterClose(t *testing.T) {
func TestWorkerPoolSubmitAfterClose(t *testing.T) {
wp := workerpool.New(runtime.NumCPU())
wp.Close()
if err := wp.Submit("dummy", nil); err != workerpool.ErrClosed {
if err := wp.Submit("dummy", nil); !errors.Is(err, workerpool.ErrClosed) {
t.Fatalf("got %v; want %v", err, workerpool.ErrClosed)
}
}
Expand All @@ -346,10 +347,10 @@ func TestWorkerPoolManyClose(t *testing.T) {
}

// calling Close() more than once should always return an error.
if err := wp.Close(); err != workerpool.ErrClosed {
if err := wp.Close(); !errors.Is(err, workerpool.ErrClosed) {
t.Fatalf("got %v; want %v", err, workerpool.ErrClosed)
}
if err := wp.Close(); err != workerpool.ErrClosed {
if err := wp.Close(); !errors.Is(err, workerpool.ErrClosed) {
t.Fatalf("got %v; want %v", err, workerpool.ErrClosed)
}
}
Expand Down

0 comments on commit f3aa07d

Please sign in to comment.