Skip to content

Commit

Permalink
Merge pull request kubernetes#5595 from piosz/guestbook_test
Browse files Browse the repository at this point in the history
Added waiting for new entry in kubectl e2e test
  • Loading branch information
rjnagal committed Mar 18, 2015
2 parents 1e5eec6 + 04ea0a8 commit 15ea997
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const (
redisMasterSelector = "name=redis-master"
redisSlaveSelector = "name=redis-slave"
kubectlProxyPort = 8011
guestbookResponseTimeout = 10 * time.Minute
guestbookStartupTimeout = 10 * time.Minute
guestbookResponseTimeout = time.Minute
)

var _ = Describe("kubectl", func() {
Expand Down Expand Up @@ -111,40 +112,31 @@ var _ = Describe("kubectl", func() {
})

func validateGuestbookApp(c *client.Client) {
// Wait for frontend to serve content.
serving := false
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
entry, err := makeRequestToGuestbook(c, "get", "")
if err == nil && entry == `{"data": ""}` {
serving = true
break
}
}
if !serving {
Failf("Frontend service did not start serving content in %v seconds", guestbookResponseTimeout.Seconds())
Logf("Waiting for frontend to serve content.")
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout) {
Failf("Frontend service did not start serving content in %v seconds.", guestbookStartupTimeout.Seconds())
}

// Try to add a new entry to the guestbook.
added := false
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
result, err := makeRequestToGuestbook(c, "set", "TestEntry")
if err == nil && result == `{"message": "Updated"}` {
added = true
break
}
}
if !added {
Failf("Cannot added new entry in %v seconds", guestbookResponseTimeout.Seconds())
Logf("Trying to add a new entry to the guestbook.")
if !waitForGuestbookResponse(c, "set", "TestEntry", `{"message": "Updated"}`, guestbookResponseTimeout) {
Failf("Cannot added new entry in %v seconds.", guestbookResponseTimeout.Seconds())
}

// Verify that entry is correctly added to the guestbook.
entry, err := makeRequestToGuestbook(c, "get", "")
if err != nil {
Failf("Request to the guestbook failed with: %v", err)
Logf("Verifying that added entry can be retrieved.")
if !waitForGuestbookResponse(c, "get", "", `{"data": "TestEntry"}`, guestbookResponseTimeout) {
Failf("Entry to guestbook wasn't correctly added in %v seconds.", guestbookResponseTimeout.Seconds())
}
if entry != `{"data": "TestEntry"}` {
Failf("Wrong entry received: %v", entry)
}

// Returns whether received expected response from guestbook on time.
func waitForGuestbookResponse(c *client.Client, cmd, arg, expectedResponse string, timeout time.Duration) bool {
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
res, err := makeRequestToGuestbook(c, cmd, arg)
if err == nil && res == expectedResponse {
return true
}
}
return false
}

func makeRequestToGuestbook(c *client.Client, cmd, value string) (string, error) {
Expand Down

0 comments on commit 15ea997

Please sign in to comment.