-
Notifications
You must be signed in to change notification settings - Fork 157
Update build execution time #335
Changes from all commits
dae3fed
3f17b56
b01d6af
e028b2f
9d5e48b
958b00b
b0809d6
c09dbdc
73f1478
6e1fcdd
45bd5c0
fbd2d41
eb0ea68
7286782
61b4568
6fc208c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"log" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
kuberrors "k8s.io/apimachinery/pkg/api/errors" | ||
|
@@ -82,6 +83,7 @@ func TestSimpleBuild(t *testing.T) { | |
Name: buildName, | ||
}, | ||
Spec: v1alpha1.BuildSpec{ | ||
Timeout: "40s", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use an actual There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a great idea. I have updated the PR with this change. |
||
Steps: []corev1.Container{{ | ||
Image: "busybox", | ||
Args: []string{"echo", "simple"}, | ||
|
@@ -120,3 +122,90 @@ func TestFailingBuild(t *testing.T) { | |
t.Fatalf("watchBuild did not return expected error: %v", err) | ||
} | ||
} | ||
|
||
func TestBuildLowTimeout(t *testing.T) { | ||
clients := setup(t) | ||
|
||
buildName := "build-low-timeout" | ||
buildTimeout := "50s" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: |
||
if _, err := clients.buildClient.builds.Create(&v1alpha1.Build{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: buildTestNamespace, | ||
Name: buildName, | ||
}, | ||
Spec: v1alpha1.BuildSpec{ | ||
Timeout: buildTimeout, | ||
Steps: []corev1.Container{{ | ||
Name: "lowtimeoutstep", | ||
Image: "ubuntu", | ||
Command: []string{"/bin/bash"}, | ||
Args: []string{"-c", "sleep 2000"}, | ||
}}, | ||
}, | ||
}); err != nil { | ||
t.Fatalf("Error creating build: %v", err) | ||
} | ||
|
||
b, err := clients.buildClient.watchBuild(buildName) | ||
if err == nil { | ||
t.Error("watchBuild did not return expected BuildTimeout error") | ||
} | ||
|
||
if &b.Status == nil { | ||
t.Fatalf("wanted build status to be set; got nil") | ||
} | ||
|
||
successCondition := b.Status.GetCondition(v1alpha1.BuildSucceeded) | ||
|
||
if successCondition == nil { | ||
t.Fatalf("wanted build status to be set; got %q", b.Status) | ||
} | ||
|
||
// verify reason for build failure is timeout | ||
if successCondition.Reason != "BuildTimeout" { | ||
t.Fatalf("wanted BuildTimeout; got %q", successCondition.Reason) | ||
} | ||
buildDuration := b.Status.CompletionTime.Time.Sub(b.Status.StartTime.Time).Seconds() | ||
lowerEnd, err := time.ParseDuration(buildTimeout) | ||
if err != nil { | ||
t.Errorf("Error parsing build duration: %v", err) | ||
} | ||
higherEnd := 90 * time.Second // build timeout + 30 sec poll time + 10 sec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this value is intended to be based on
That way if we change |
||
|
||
if !(buildDuration >= lowerEnd.Seconds() && buildDuration < higherEnd.Seconds()) { | ||
t.Fatalf("Expected the build duration to be within range %.2fs to %.2fs; but got build duration: %f, start time: %q and completed time: %q \n", | ||
lowerEnd.Seconds(), | ||
higherEnd.Seconds(), | ||
buildDuration, | ||
b.Status.StartTime.Time, | ||
b.Status.CompletionTime.Time, | ||
) | ||
} | ||
} | ||
|
||
// TestPendingBuild tests that a build with non existent node selector will remain in pending | ||
// state until watch timeout. | ||
func TestPendingBuild(t *testing.T) { | ||
clients := setup(t) | ||
|
||
buildName := "pending-build" | ||
if _, err := clients.buildClient.builds.Create(&v1alpha1.Build{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: buildTestNamespace, | ||
Name: buildName, | ||
}, | ||
Spec: v1alpha1.BuildSpec{ | ||
NodeSelector: map[string]string{"disk": "fake-ssd"}, | ||
Steps: []corev1.Container{{ | ||
Image: "busybox", | ||
Args: []string{"false"}, // fails. | ||
}}, | ||
}, | ||
}); err != nil { | ||
t.Fatalf("Error creating build: %v", err) | ||
} | ||
|
||
if _, err := clients.buildClient.watchBuild(buildName); err == nil { | ||
t.Fatalf("watchBuild did not return watch timeout error") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These quotes aren't necessary right? I don't feel strongly about removing them, I just want to make sure this all works if a user doesn't explicitly quote the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quotes are not necessary. When I changed the type into string I might have gone on a spree to add quotes everywhere :D I will follow up with a PR to address all your comments.