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/metropolis/pkg/event/etcd/etcd_test.go b/metropolis/pkg/event/etcd/etcd_test.go
index e7e1227..6173732 100644
--- a/metropolis/pkg/event/etcd/etcd_test.go
+++ b/metropolis/pkg/event/etcd/etcd_test.go
@@ -210,7 +210,9 @@
return
}
if err != nil {
- t.Fatalf("Get: %v", err)
+ t.Errorf("Get: %v", err)
+ close(c)
+ return
}
c <- got.Value
}
diff --git a/metropolis/pkg/socksproxy/socksproxy_test.go b/metropolis/pkg/socksproxy/socksproxy_test.go
index 1f384f6..0132ab3 100644
--- a/metropolis/pkg/socksproxy/socksproxy_test.go
+++ b/metropolis/pkg/socksproxy/socksproxy_test.go
@@ -35,7 +35,8 @@
go func() {
err := http.Serve(lisSrv, mux)
if err != nil {
- t.Fatalf("http.Serve: %v", err)
+ t.Errorf("http.Serve: %v", err)
+ return
}
}()
@@ -47,7 +48,8 @@
go func() {
err := Serve(ctx, HostHandler, lisPrx)
if err != nil && !errors.Is(err, ctx.Err()) {
- t.Fatalf("proxy.Serve: %v", err)
+ t.Errorf("proxy.Serve: %v", err)
+ return
}
}()
@@ -122,7 +124,8 @@
go func() {
err := Serve(ctx, handler, lisPrx)
if err != nil && !errors.Is(err, ctx.Err()) {
- t.Fatalf("proxy.Serve: %v", err)
+ t.Errorf("proxy.Serve: %v", err)
+ return
}
}()