MCPcopy
hub / github.com/labstack/echo / TestClientCancelConnectionResultsHTTPCode499

Function TestClientCancelConnectionResultsHTTPCode499

middleware/proxy_test.go:360–388  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

358}
359
360func 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
390type testProvider struct {
391 commonBalancer

Callers

nothing calls this directly

Calls 8

NewRandomBalancerFunction · 0.85
ProxyWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
AddMethod · 0.65
AddTargetMethod · 0.65
WriteHeaderMethod · 0.45
CloseMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…