From 895ae9ce7ecc90f6b6cdbcd7b35b7d07f77e18a6 Mon Sep 17 00:00:00 2001 From: Lin Meyer Date: Tue, 6 Oct 2020 13:00:54 -0500 Subject: [PATCH] Added unit tests for WAIT_FOR_ENVOY_TIMEOUT --- main_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main_test.go b/main_test.go index 91f132b..05d8a02 100644 --- a/main_test.go +++ b/main_test.go @@ -161,3 +161,21 @@ func TestWaitTillTimeoutForEnvoy(t *testing.T) { } } } + +// Tests scuttle will continue after WAIT_FOR_ENVOY_TIMEOUT expires and enovy is not ready +func TestWaitForEnvoyTimeoutContinueWithoutEnvoy(t *testing.T) { + fmt.Println("Starting TestWaitForEnvoyTimeoutContinueWithoutEnvoy") + os.Setenv("WAIT_FOR_ENVOY_TIMEOUT", "5s") + os.Setenv("ENVOY_ADMIN_API", badServer.URL) + initTestingEnv() + blockingCtx := waitForEnvoy() + <-blockingCtx.Done() + err := blockingCtx.Err() + if err == nil || !errors.Is(err, context.DeadlineExceeded) { + fmt.Println("TestWaitForEnvoyTimeoutContinueWithoutEnvoy err", err) + // Err is nil (enovy is up) + // or Err is set, but is not a cancellation err + // we expect a cancellation when the time is up + t.Fail() + } +}