Handle timeout errors in test client cleanup

Added a check in the client cleanup function to skip the test if the client connection fails due to a timeout. This ensures that network-related timeouts do not cause test failures, providing more reliable test outcomes.
This commit is contained in:
Winni Neessen 2024-10-27 12:10:51 +01:00
parent 056ec60734
commit b510d2654c
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -2579,6 +2579,10 @@ func TestClient_Send(t *testing.T) {
} }
t.Cleanup(func() { t.Cleanup(func() {
if err := client.Close(); err != nil { if err := client.Close(); err != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
t.Skip("failed to connect to the test server due to timeout")
}
t.Errorf("failed to close client: %s", err) t.Errorf("failed to close client: %s", err)
} }
}) })