testport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 9 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 testport hands tests loopback ports a server can bind again after it stops: a broker or node restarted on its old port must find that port free while it is down.

A port in the operating system's ephemeral range is not: any outgoing connection can be given it as its source port, and many tests running at once open thousands of them. The ports here are drawn from below every default ephemeral range (Linux 32768 to 60999, Windows and macOS 49152 to 65535), so only a listener can take one.

Each port handed out is also reserved, by a lock file under the temporary directory, until the test that took it ends. Another caller, in this test binary or another one running at the same time, skips a reserved port, and never binds it to check it is free, so a port stays the test's while its server is down.

It is a test helper. Production code must not import it.

Index

Constants

View Source
const (
	RangeLow  = 20000
	RangeHigh = 32768
)

RangeLow and RangeHigh bound the ports Free hands out.

Variables

This section is empty.

Functions

func Free

func Free(t testing.TB, n int) []int

Free reserves n distinct loopback ports in [RangeLow, RangeHigh) that can be bound now, until t ends. Nothing listens on them: the caller binds them.

Types

This section is empty.

Jump to

Keyboard shortcuts

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