peertest

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: AGPL-3.0 Imports: 15 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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pair

func Pair(t testing.TB) (client, host *peer.Conn)

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 PairOpts

func PairOpts(t testing.TB, services *peer.Registry, o Options) (client, host *peer.Conn)

PairOpts is PairWith with host options.

func PairWith

func PairWith(t testing.TB, services *peer.Registry) (client, host *peer.Conn)

PairWith is Pair with an explicit host-side registry.

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.

Jump to

Keyboard shortcuts

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