testhttp

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

server.go —— agentd 测试 HTTP fixture 的 TCP 连接收口与 loopback 拨号重试。

职责:包装 httptest 的服务端 Accept 与测试 client 的 DialContext,使临时端口 在 Darwin 上更快释放,并把极窄的 EADDRNOTAVAIL 重试限制在测试 fixture。 边界:本包只供测试导入;不修改生产 client.New、不重试 Client.Do;非 loopback 地址与非指定错误都只尝试一次。

Index

Constants

View Source
const (
	// MaxDialAttempts bounds retries for a single loopback address-allocation failure.
	MaxDialAttempts = 4
)

Variables

This section is empty.

Functions

func CloseIdleConnections

func CloseIdleConnections()

CloseIdleConnections closes tracked idle transports and the standard default transport. It is intentionally separate from request cancellation.

func ConfigureClient

func ConfigureClient(client *http.Client)

ConfigureClient replaces only a *http.Transport's dial hooks. A nil Transport is cloned from http.DefaultTransport so the process-global default is never mutated; a non-*http.Transport is intentionally left unchanged because it has no safe TCP hook.

func NewServer

func NewServer(t testing.TB, handler http.Handler) *httptest.Server

NewServer starts a linger-enabled httptest server, configures the default client and registers cleanup that closes the server before tracked idle transports.

func NewUnstartedServer

func NewUnstartedServer(t testing.TB, handler http.Handler) *httptest.Server

NewUnstartedServer returns a linger-enabled server whose caller may replace Listener or modify Config before Start. The caller must call ConfigureClient(ts.Client()) after Start because httptest creates its client inside Start.

Types

type DialContext

type DialContext func(context.Context, string, string) (net.Conn, error)

DialContext is the context-aware dial signature wrapped by the fixture.

func RetryDialContext

func RetryDialContext(base DialContext) DialContext

RetryDialContext retries only the two Darwin loopback address-allocation errors and only up to MaxDialAttempts. A successful loopback connection gets client-side linger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL