(t *testing.T)
| 358 | } |
| 359 | |
| 360 | func TestClientCancelConnectionResultsHTTPCode499(t *testing.T) { |
| 361 | var timeoutStop sync.WaitGroup |
| 362 | timeoutStop.Add(1) |
| 363 | HTTPTarget := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 364 | timeoutStop.Wait() // wait until we have canceled the request |
| 365 | w.WriteHeader(http.StatusOK) |
| 366 | })) |
| 367 | defer HTTPTarget.Close() |
| 368 | targetURL, _ := url.Parse(HTTPTarget.URL) |
| 369 | target := &ProxyTarget{ |
| 370 | Name: "target", |
| 371 | URL: targetURL, |
| 372 | } |
| 373 | rb := NewRandomBalancer(nil) |
| 374 | assert.True(t, rb.AddTarget(target)) |
| 375 | e := echo.New() |
| 376 | e.Use(ProxyWithConfig(ProxyConfig{Balancer: rb})) |
| 377 | rec := httptest.NewRecorder() |
| 378 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 379 | ctx, cancel := context.WithCancel(req.Context()) |
| 380 | req = req.WithContext(ctx) |
| 381 | go func() { |
| 382 | time.Sleep(10 * time.Millisecond) |
| 383 | cancel() |
| 384 | }() |
| 385 | e.ServeHTTP(rec, req) |
| 386 | timeoutStop.Done() |
| 387 | assert.Equal(t, 499, rec.Code) |
| 388 | } |
| 389 | |
| 390 | type testProvider struct { |
| 391 | commonBalancer |
nothing calls this directly
no test coverage detected
searching dependent graphs…