testHealthCheck verifies that when a proxy client serves the given instance, the readiness endpoint serves http.StatusOK.
(t *testing.T, connName string)
| 106 | // testHealthCheck verifies that when a proxy client serves the given instance, |
| 107 | // the readiness endpoint serves http.StatusOK. |
| 108 | func testHealthCheck(t *testing.T, connName string) { |
| 109 | t.Helper() |
| 110 | ctx, cancel := context.WithTimeout(context.Background(), connTestTimeout) |
| 111 | defer cancel() |
| 112 | |
| 113 | args := []string{connName, "--health-check"} |
| 114 | // Start the proxy. |
| 115 | p, err := StartProxy(ctx, args...) |
| 116 | if err != nil { |
| 117 | t.Fatalf("unable to start proxy: %v", err) |
| 118 | } |
| 119 | defer p.Close() |
| 120 | _, err = p.WaitForServe(ctx) |
| 121 | if err != nil { |
| 122 | t.Fatal(err) |
| 123 | } |
| 124 | |
| 125 | var ( |
| 126 | gErr error |
| 127 | resp *http.Response |
| 128 | ) |
| 129 | for i := 0; i < 10; i++ { |
| 130 | resp, gErr = http.Get("http://localhost:9090/readiness") |
| 131 | if gErr != nil { |
| 132 | time.Sleep(100 * time.Millisecond) |
| 133 | continue |
| 134 | } |
| 135 | if resp.StatusCode != http.StatusOK { |
| 136 | time.Sleep(100 * time.Millisecond) |
| 137 | continue |
| 138 | } |
| 139 | return // The response is OK, the test passes. |
| 140 | } |
| 141 | if gErr != nil { |
| 142 | t.Fatalf("HTTP GET failed: %v", gErr) |
| 143 | } |
| 144 | respBody, dErr := httputil.DumpResponse(resp, true) |
| 145 | if dErr != nil { |
| 146 | t.Fatalf("failed to dump HTTP response: %v", dErr) |
| 147 | } |
| 148 | t.Fatalf("HTTP GET failed: response =\n%v", string(respBody)) |
| 149 | } |
no test coverage detected