Skip to content

Commit f163021

Browse files
committed
remove t.Fatal calls from non test goroutines
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>
1 parent 5bba80b commit f163021

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

pkg/queue/queue_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func TestSimpleSyncQueue_Basic(t *testing.T) {
3838
numConsumers := 5
3939
consumersWG := sync.WaitGroup{}
4040
consumersWG.Add(numConsumers)
41+
var fatal bool
4142
for i := 0; i < numConsumers; i++ {
43+
if fatal {
44+
break
45+
}
4246
go func(i int) {
4347
defer consumersWG.Done()
4448
for {
@@ -47,14 +51,19 @@ func TestSimpleSyncQueue_Basic(t *testing.T) {
4751
return
4852
}
4953
if !strings.HasPrefix(item.(string), "ns1/vm") {
50-
t.Fatal("received item from queue after shutdown")
54+
fatal = true
55+
return
5156
}
5257
atomic.AddInt32(&countConsumed, 1)
5358
time.Sleep(3 * time.Millisecond)
5459
}
5560
}(i)
5661
}
5762

63+
if fatal {
64+
t.Fatal("received item from queue after shutdown")
65+
}
66+
5867
producersWG.Wait()
5968
t.Log("shutting queue down")
6069
q.Shutdown()
@@ -82,7 +91,11 @@ func TestSimpleSyncQueue_Duplicate(t *testing.T) {
8291
numConsumers := 5
8392
consumersWG := sync.WaitGroup{}
8493
consumersWG.Add(numConsumers)
94+
var fatal bool
8595
for i := 0; i < numConsumers; i++ {
96+
if fatal {
97+
break
98+
}
8699
go func(i int) {
87100
defer consumersWG.Done()
88101
for {
@@ -91,14 +104,19 @@ func TestSimpleSyncQueue_Duplicate(t *testing.T) {
91104
return
92105
}
93106
if !strings.HasPrefix(item.(string), "ns1/vm") {
94-
t.Fatal("received item from queue after shutdown")
107+
fatal = true
108+
return
95109
}
96110
atomic.AddInt32(&countConsumed, 1)
97111
time.Sleep(3 * time.Millisecond)
98112
}
99113
}(i)
100114
}
101115

116+
if fatal {
117+
t.Fatal("received item from queue after shutdown")
118+
}
119+
102120
t.Log("shutting queue down")
103121
q.Shutdown()
104122
t.Log("enqueing message after shutdown")

0 commit comments

Comments
 (0)