(t *testing.T)
| 281 | } |
| 282 | |
| 283 | func TestCreateBackoffManager(t *testing.T) { |
| 284 | |
| 285 | theUrl, _ := url.Parse("http://localhost") |
| 286 | |
| 287 | // 1 second base backoff + duration of 2 seconds -> exponential backoff for requests. |
| 288 | os.Setenv(envBackoffBase, "1") |
| 289 | os.Setenv(envBackoffDuration, "2") |
| 290 | backoff := readExpBackoffConfig() |
| 291 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 292 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 293 | if backoff.CalculateBackoff(theUrl)/time.Second != 2 { |
| 294 | t.Errorf("Backoff env not working.") |
| 295 | } |
| 296 | |
| 297 | // 0 duration -> no backoff. |
| 298 | os.Setenv(envBackoffBase, "1") |
| 299 | os.Setenv(envBackoffDuration, "0") |
| 300 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 301 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 302 | backoff = readExpBackoffConfig() |
| 303 | if backoff.CalculateBackoff(theUrl)/time.Second != 0 { |
| 304 | t.Errorf("Zero backoff duration, but backoff still occurring.") |
| 305 | } |
| 306 | |
| 307 | // No env -> No backoff. |
| 308 | os.Setenv(envBackoffBase, "") |
| 309 | os.Setenv(envBackoffDuration, "") |
| 310 | backoff = readExpBackoffConfig() |
| 311 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 312 | backoff.UpdateBackoff(theUrl, nil, 500) |
| 313 | if backoff.CalculateBackoff(theUrl)/time.Second != 0 { |
| 314 | t.Errorf("Backoff should have been 0.") |
| 315 | } |
| 316 | |
| 317 | } |
| 318 | |
| 319 | func testServerEnv(t *testing.T, statusCode int) (*httptest.Server, *utiltesting.FakeHandler, *metav1.Status) { |
| 320 | status := &metav1.Status{TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Status"}, Status: fmt.Sprintf("%s", metav1.StatusSuccess)} |
nothing calls this directly
no test coverage detected