Skip to content

Commit

Permalink
Added waiting for new entry in kubectl e2e test
Browse files Browse the repository at this point in the history
The test tends to fail because after an entry is added to data-base it takes
some time to replicate it from redis-master to redis-slave
  • Loading branch information
piosz committed Mar 18, 2015
1 parent faab509 commit 04ea0a8
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 04ea0a8

Please sign in to comment.