MCPcopy
hub / github.com/caddyserver/caddy / deadUpstreamAddr

Function deadUpstreamAddr

modules/caddyhttp/reverseproxy/retries_test.go:66–75  ·  view source on GitHub ↗

deadUpstreamAddr returns a TCP address that is guaranteed to refuse connections: we bind a listener, note its address, close it immediately, and return the address. Any dial to that address will get ECONNREFUSED.

(t *testing.T)

Source from the content-addressed store, hash-verified

64// connections: we bind a listener, note its address, close it immediately,
65// and return the address. Any dial to that address will get ECONNREFUSED.
66func deadUpstreamAddr(t *testing.T) string {
67 t.Helper()
68 ln, err := net.Listen("tcp", "127.0.0.1:0")
69 if err != nil {
70 t.Fatalf("failed to create dead upstream listener: %v", err)
71 }
72 addr := ln.Addr().String()
73 ln.Close()
74 return addr
75}
76
77// testTransport wraps http.Transport to:
78// 1. Set the URL scheme to "http" when it is empty (matching what

Callers 2

TestDialErrorBodyRetryFunction · 0.85

Calls 4

ListenMethod · 0.80
AddrMethod · 0.80
StringMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected