mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #5595 from piosz/guestbook_test
Added waiting for new entry in kubectl e2e test
This commit is contained in:
commit
15ea997983
@ -40,7 +40,8 @@ const (
|
|||||||
redisMasterSelector = "name=redis-master"
|
redisMasterSelector = "name=redis-master"
|
||||||
redisSlaveSelector = "name=redis-slave"
|
redisSlaveSelector = "name=redis-slave"
|
||||||
kubectlProxyPort = 8011
|
kubectlProxyPort = 8011
|
||||||
guestbookResponseTimeout = 10 * time.Minute
|
guestbookStartupTimeout = 10 * time.Minute
|
||||||
|
guestbookResponseTimeout = time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("kubectl", func() {
|
var _ = Describe("kubectl", func() {
|
||||||
@ -111,40 +112,31 @@ var _ = Describe("kubectl", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
func validateGuestbookApp(c *client.Client) {
|
func validateGuestbookApp(c *client.Client) {
|
||||||
// Wait for frontend to serve content.
|
Logf("Waiting for frontend to serve content.")
|
||||||
serving := false
|
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout) {
|
||||||
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
|
Failf("Frontend service did not start serving content in %v seconds.", guestbookStartupTimeout.Seconds())
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to add a new entry to the guestbook.
|
Logf("Trying to add a new entry to the guestbook.")
|
||||||
added := false
|
if !waitForGuestbookResponse(c, "set", "TestEntry", `{"message": "Updated"}`, guestbookResponseTimeout) {
|
||||||
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
|
Failf("Cannot added new entry in %v seconds.", guestbookResponseTimeout.Seconds())
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that entry is correctly added to the guestbook.
|
Logf("Verifying that added entry can be retrieved.")
|
||||||
entry, err := makeRequestToGuestbook(c, "get", "")
|
if !waitForGuestbookResponse(c, "get", "", `{"data": "TestEntry"}`, guestbookResponseTimeout) {
|
||||||
if err != nil {
|
Failf("Entry to guestbook wasn't correctly added in %v seconds.", guestbookResponseTimeout.Seconds())
|
||||||
Failf("Request to the guestbook failed with: %v", err)
|
|
||||||
}
|
}
|
||||||
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) {
|
func makeRequestToGuestbook(c *client.Client, cmd, value string) (string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user