Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
fix(tests): make curl loop a few times
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Oct 19, 2014
1 parent 4b536a7 commit 861b026
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions tests/utils/itutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,42 @@ func GetGlobalConfig() *DeisTestConfig {
return &envCfg
}

func doCurl(url string) ([]byte, error) {
response, err := http.Get(url)
if err != nil {
return nil, err
}

body, err := ioutil.ReadAll(response.Body)

if !strings.Contains(string(body), "Powered by Deis") {
return nil, fmt.Errorf("App not started")
}

return body, nil
}

// Curl connects to a Deis endpoint to see if the example app is running.
func Curl(t *testing.T, params *DeisTestConfig) {
url := "http://" + params.AppName + "." + params.Domain
// FIXME: make an initial request to nginx to remove stale worker
_, err := http.Get(url)
if err != nil {
t.Fatalf("not reachable:\n%v", err)

// FIXME: try the curl a few times
for i := 0; i < 20; i++ {
body, err := doCurl(url)
if err == nil {
fmt.Println(string(body))
return
}
time.Sleep(1 * time.Second)
}
// FIXME: sleep a bit before curling
time.Sleep(5000 * time.Millisecond)
response, err := http.Get(url)

// once more to fail with an error
body, err := doCurl(url)
if err != nil {
t.Fatalf("not reachable:\n%v", err)
t.Fatal(err)
}
body, err := ioutil.ReadAll(response.Body)
fmt.Println(string(body))
if !strings.Contains(string(body), "Powered by Deis") {
t.Fatalf("App not started")
}

}

// AuthCancel tests whether `deis auth:cancel` destroys a user's account.
Expand Down

0 comments on commit 861b026

Please sign in to comment.