From 1ecd4053de72463c2c6a16e45263a76a806b32cc Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Sat, 24 Feb 2024 19:26:29 +0100 Subject: [PATCH] ktesting: skip timing check in unit test Extending the duration and the allowed delta in f6682370b1 was still not enough to make the unit test run reliably in pull-kubernetes-unit. Now it uses the original, stricter timing again, but only when run locally. In Prow (detected by checking the "CI" env variable), the duration check is skipped. --- test/utils/ktesting/contexthelper_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/utils/ktesting/contexthelper_test.go b/test/utils/ktesting/contexthelper_test.go index 548f99a975f..37533593c80 100644 --- a/test/utils/ktesting/contexthelper_test.go +++ b/test/utils/ktesting/contexthelper_test.go @@ -19,6 +19,8 @@ package ktesting import ( "context" "errors" + "os" + "strings" "testing" "time" @@ -112,7 +114,17 @@ func TestCause(t *testing.T) { if tt.expectDeadline != 0 { actualDeadline, ok := ctx.Deadline() if assert.True(t, ok, "should have had a deadline") { - assert.InDelta(t, time.Until(actualDeadline), tt.expectDeadline, float64(time.Second), "remaining time till Deadline()") + // Testing timing behavior is unreliable in Prow because + // the test runs in parallel with several others. + // Therefore this check is skipped if a CI environment is + // detected. + ci, _ := os.LookupEnv("CI") + switch strings.ToLower(ci) { + case "yes", "true", "1": + // Skip. + default: + assert.InDelta(t, time.Until(actualDeadline), tt.expectDeadline, float64(time.Second), "remaining time till Deadline()") + } } } time.Sleep(tt.sleep)