Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes(#598): checks for namespace creation instead of waiting #611

Merged
merged 3 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
maximilien marked this conversation as resolved.
Show resolved Hide resolved
}
}

// 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 {
maximilien marked this conversation as resolved.
Show resolved Hide resolved
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) {
maximilien marked this conversation as resolved.
Show resolved Hide resolved
return true
}

Expand Down