Skip to content

Commit

Permalink
fixes(#598): checks for namespace creation instead of waiting (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien authored and knative-prow-robot committed Jan 24, 2020
1 parent ff7dffc commit 606de80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
26 changes: 21 additions & 5 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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{})
Expand All @@ -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
}

Expand Down

0 comments on commit 606de80

Please sign in to comment.