Skip to content

Commit

Permalink
remove t.Fatal calls from non test goroutines
Browse files Browse the repository at this point in the history
Before this commit, running `go vet ./...` would return:
```
pkg/queue/queue_test.go:50:6: call to (*T).Fatal from a non-test goroutine
pkg/queue/queue_test.go:94:6: call to (*T).Fatal from a non-test goroutine
```

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed May 26, 2023
1 parent 5bba80b commit f163021
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func TestSimpleSyncQueue_Basic(t *testing.T) {
numConsumers := 5
consumersWG := sync.WaitGroup{}
consumersWG.Add(numConsumers)
var fatal bool
for i := 0; i < numConsumers; i++ {
if fatal {
break
}
go func(i int) {
defer consumersWG.Done()
for {
Expand All @@ -47,14 +51,19 @@ func TestSimpleSyncQueue_Basic(t *testing.T) {
return
}
if !strings.HasPrefix(item.(string), "ns1/vm") {
t.Fatal("received item from queue after shutdown")
fatal = true
return
}
atomic.AddInt32(&countConsumed, 1)
time.Sleep(3 * time.Millisecond)
}
}(i)
}

if fatal {
t.Fatal("received item from queue after shutdown")
}

producersWG.Wait()
t.Log("shutting queue down")
q.Shutdown()
Expand Down Expand Up @@ -82,7 +91,11 @@ func TestSimpleSyncQueue_Duplicate(t *testing.T) {
numConsumers := 5
consumersWG := sync.WaitGroup{}
consumersWG.Add(numConsumers)
var fatal bool
for i := 0; i < numConsumers; i++ {
if fatal {
break
}
go func(i int) {
defer consumersWG.Done()
for {
Expand All @@ -91,14 +104,19 @@ func TestSimpleSyncQueue_Duplicate(t *testing.T) {
return
}
if !strings.HasPrefix(item.(string), "ns1/vm") {
t.Fatal("received item from queue after shutdown")
fatal = true
return
}
atomic.AddInt32(&countConsumed, 1)
time.Sleep(3 * time.Millisecond)
}
}(i)
}

if fatal {
t.Fatal("received item from queue after shutdown")
}

t.Log("shutting queue down")
q.Shutdown()
t.Log("enqueing message after shutdown")
Expand Down

0 comments on commit f163021

Please sign in to comment.