diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 0da5b3c24c..5648b5ccfb 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,6 +18,10 @@ |=== | | Description | PR +| 🧽 +| checks for namespace creation instead of waiting +| https://github.com/knative/client/pull/611[#611] + | 🎁 | Add `kn trigger update` for updating triggers | https://github.com/knative/client/pull/562[#562] diff --git a/test/e2e/common.go b/test/e2e/common.go index 19b9503f8a..1b5d175965 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -41,7 +41,7 @@ type runOpts struct { const ( KnDefaultTestImage string = "gcr.io/knative-samples/helloworld-go" MaxRetries int = 10 - RetrySleepDuration time.Duration = 30 * time.Second + RetrySleepDuration time.Duration = 5 * time.Second ) var m sync.Mutex @@ -66,7 +66,7 @@ func (test *e2eTest) Setup(t *testing.T) { test.kn = kn{t, test.env.Namespace, Logger{}} if test.createNamespaceOnSetup { test.CreateTestNamespace(t, test.env.Namespace) - time.Sleep(20 * time.Second) + test.WaitForNamespaceCreated(t, test.env.Namespace) } } @@ -127,14 +127,23 @@ func (test *e2eTest) DeleteTestNamespace(t *testing.T, namespace string) { // WaitForNamespaceDeleted wait until namespace is deleted func (test *e2eTest) WaitForNamespaceDeleted(t *testing.T, namespace string) { logger := Logger{} - deleted := checkNamespaceDeleted(t, namespace, MaxRetries, logger) + deleted := checkNamespace(t, namespace, false, MaxRetries, logger) if !deleted { t.Fatalf("Error deleting namespace %s, timed out", namespace) } } +// WaitForNamespaceCreated wait until namespace is created +func (test *e2eTest) WaitForNamespaceCreated(t *testing.T, namespace string) { + logger := Logger{} + created := checkNamespace(t, namespace, true, MaxRetries, logger) + if !created { + t.Fatalf("Error creating namespace %s, timed out", namespace) + } +} + // Private functions -func checkNamespaceDeleted(t *testing.T, namespace string, maxRetries int, logger Logger) bool { +func checkNamespace(t *testing.T, namespace string, created bool, maxRetries int, logger Logger) bool { kubectlGetNamespace := func() (string, error) { kubectl := kubectl{t, logger} return kubectl.RunWithOpts([]string{"get", "namespace"}, runOpts{}) @@ -143,7 +152,14 @@ func checkNamespaceDeleted(t *testing.T, namespace string, maxRetries int, logge retries := 0 for retries < MaxRetries { output, _ := kubectlGetNamespace() - if !strings.Contains(output, namespace) { + + // check for namespace deleted + if !created && !strings.Contains(output, namespace) { + return true + } + + // check for namespace created + if created && strings.Contains(output, namespace) { return true }