github.com/dustinrc/deis@v1.10.1-0.20150917223407-0894a5fb979e/tests/healthcheck_test.go (about) 1 // +build integration 2 3 package tests 4 5 import ( 6 "fmt" 7 "net/http" 8 "testing" 9 10 "github.com/deis/deis/tests/utils" 11 ) 12 13 var ( 14 healthcheckGoodCmd = "config:set HEALTHCHECK_URL=/ --app={{.AppName}}" 15 ) 16 17 func TestHealthcheck(t *testing.T) { 18 client := utils.HTTPClient() 19 cfg := healthcheckSetup(t) 20 done := make(chan bool, 1) 21 url := fmt.Sprintf("http://%s.%s", cfg.AppName, cfg.Domain) 22 23 utils.Execute(t, healthcheckGoodCmd, cfg, false, "/") 24 go func() { 25 // there should never be any downtime during these health check operations 26 psScaleTest(t, cfg, psScaleCmd) 27 cfg.ProcessNum = "1" 28 psScaleTest(t, cfg, psScaleCmd) 29 // kill healthcheck goroutine 30 done <- true 31 }() 32 33 // run health checks in parallel while performing operations 34 fmt.Printf("starting health checks at %s\n", url) 35 loop: 36 for { 37 select { 38 case <-done: 39 fmt.Println("done performing health checks") 40 break loop 41 default: 42 doHealthCheck(t, client, url) 43 } 44 } 45 utils.AppsDestroyTest(t, cfg) 46 } 47 48 func healthcheckSetup(t *testing.T) *utils.DeisTestConfig { 49 cfg := utils.GetGlobalConfig() 50 cfg.AppName = "healthchecksample" 51 utils.Execute(t, authLoginCmd, cfg, false, "") 52 utils.Execute(t, gitCloneCmd, cfg, false, "") 53 if err := utils.Chdir(cfg.ExampleApp); err != nil { 54 t.Fatal(err) 55 } 56 utils.Execute(t, appsCreateCmd, cfg, false, "") 57 utils.Execute(t, gitPushCmd, cfg, false, "") 58 utils.CurlApp(t, *cfg) 59 if err := utils.Chdir(".."); err != nil { 60 t.Fatal(err) 61 } 62 return cfg 63 } 64 65 func doHealthCheck(t *testing.T, client *http.Client, url string) { 66 response, err := client.Get(url) 67 if err != nil { 68 t.Fatalf("could not retrieve response from %s: %v\n", url, err) 69 } 70 defer response.Body.Close() 71 if response.StatusCode != http.StatusOK { 72 t.Fatalf("app had some downtime while undergoing health checks (got %d response)", response.StatusCode) 73 } 74 }