From ce6035b7384d6f690d34d35a0f81f076c66c7a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 28 Jul 2021 21:40:44 +0200 Subject: [PATCH] Add timeouts when waiting on OpenShift or the registry to start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that we terminate with the full context and pointing at the relevant code, instead of relying on the overall test suite timeout. Signed-off-by: Miloslav Trmač --- integration/openshift.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/integration/openshift.go b/integration/openshift.go index ffebfefb..34cef8b3 100644 --- a/integration/openshift.go +++ b/integration/openshift.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "context" "encoding/base64" "fmt" "io/ioutil" @@ -9,6 +10,7 @@ import ( "os/exec" "path/filepath" "strings" + "time" "github.com/docker/docker/pkg/homedir" "github.com/go-check/check" @@ -109,6 +111,8 @@ func (cluster *openshiftCluster) startMaster(c *check.C) { gotPortCheck := false gotLogCheck := false + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() for !gotPortCheck || !gotLogCheck { c.Logf("Waiting for master") select { @@ -121,6 +125,8 @@ func (cluster *openshiftCluster) startMaster(c *check.C) { c.Fatal("log check done, success message not found") } gotLogCheck = true + case <-ctx.Done(): + c.Fatalf("Timed out waiting for master: %v", ctx.Err()) } } c.Logf("OK, master started!") @@ -166,8 +172,14 @@ func (cluster *openshiftCluster) startRegistryProcess(c *check.C, port int, conf terminatePortCheck <- true }() c.Logf("Waiting for registry to start") - <-portOpen - c.Logf("OK, Registry port open") + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + defer cancel() + select { + case <-portOpen: + c.Logf("OK, Registry port open") + case <-ctx.Done(): + c.Fatalf("Timed out waiting for registry to start: %v", ctx.Err()) + } return cmd }