Documentation
¶
Overview ¶
Package peertest gives service packages a real client<->host session to test against without rendezvous, hole punching or passwords: two QUIC endpoints on loopback wired straight into the session layer.
It is test support only. Nothing outside _test.go files may import it, because the sessions it creates are unauthenticated.
Index ¶
- func Pair(t testing.TB) (client, host *peer.Conn)
- func PairOpts(t testing.TB, services *peer.Registry, o Options) (client, host *peer.Conn)
- func PairWith(t testing.TB, services *peer.Registry) (client, host *peer.Conn)
- func TryPairOpts(ctx context.Context, cleanup func(func()), services *peer.Registry, o Options) (client, host *peer.Conn, err error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Pair ¶
Pair returns a connected client and host session. The host side serves peer.HostServices, so importing a service package (which registers itself from init) is all a test needs to do. Both ends are closed when the test finishes.
func TryPairOpts ¶
func TryPairOpts(ctx context.Context, cleanup func(func()), services *peer.Registry, o Options) (client, host *peer.Conn, err error)
TryPairOpts is PairOpts for code that runs outside the test's own goroutine, such as a dial function a gateway calls in the background: it returns an error rather than failing the test, which would panic the whole run if the test had ended meanwhile, and it gives up when ctx is done. cleanup receives what closes the pair and its transports, in the order they are made; called in reverse order (as t.Cleanup does), the sessions close before their transports. On an error, what was made is closed already.
Types ¶
type Options ¶
type Options struct {
// Authorize is passed to the host's peer.Options.
Authorize func(service string) error
// NoStart returns the host end unstarted (peer.New): it serves no
// stream until the test calls Start.
NoStart bool
// Latency delays every packet either end sends by this much, so the
// round trip is twice it: what timing tests use to see how an
// operation behaves on a real network rather than on loopback.
Latency time.Duration
// Loss drops this share of the packets either end sends (0 to 1), each
// at random, as a lossy link (Wi-Fi, a phone's radio) would. The
// handshake goes through it too, which QUIC copes with.
Loss float64
}
Options tunes the host end of a test session.