treewide: fix t.Fatal calls in non-test goroutines
Functions that abruptly terminate a test, such as the
Fatal, Fatalf, FailNow, and Skip{,f,Now} methods of *testing.T,
must be called from the test goroutine itself, as they call
runtime.Goexit internally to stop the calling goroutine, not the
test.
Change-Id: I4926c802bfbb11aeec6e130b0f4fb2407879cbd4
Reviewed-on: https://review.monogon.dev/c/monogon/+/2972
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/go/net/psample/psample_test.go b/go/net/psample/psample_test.go
index 925ae0d..b01ad97 100644
--- a/go/net/psample/psample_test.go
+++ b/go/net/psample/psample_test.go
@@ -179,7 +179,8 @@
}
// Look for packets matching attributes defined in 'sa'. Signal on 'dC'
- // immediately after the expected packet has been received, then return.
+ // immediately after the expected packet has been received or an error
+ // occurred, then return.
dC := make(chan struct{})
go func() {
for {
@@ -188,7 +189,9 @@
// the sampled traffic could not have been captured, and had been
// dropped instead.
if err != nil && !errors.Is(err, syscall.ENOBUFS) {
- t.Fatalf("while receiving psamples: %v", err)
+ t.Errorf("while receiving psamples: %v", err)
+ dC <- struct{}{}
+ return
}
for _, raw := range pkts {
if sa.match(t, raw) {