porttest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 6 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 porttest picks free ports for gcpemu's own tests.

A test that listens on port 0, closes the listener and binds the port again later leaves a window in which another process can take it: the OS hands out port-0 and outgoing-connection ports from its ephemeral range, which test packages running in parallel use all the time. So ports come from 20000-32767 instead, below the ephemeral range on Linux (32768-60999), macOS and Windows (49152-65535), where only explicit binds take them. Each call starts at a random port, so parallel packages do not all probe the same ones.

A test whose code under test can take a listener the test already holds should hold its port and hand it over instead (#643, #648). Tests use this package rather than probing port 0 themselves (#743, #750).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Free

func Free(t testing.TB) int

Free returns a port that can be bound, as Window(t, 1).

func FreeUDP

func FreeUDP(t testing.TB) int

FreeUDP returns a port that a plain udp4 bind on 0.0.0.0 can take, scanning from a random port of the range. A port any IPv4 UDP socket holds is not free, even one bound with SO_REUSEADDR or SO_REUSEPORT, so a test's own mDNS port meets no other test's traffic. The code under test, or a child process, binds the port itself with SO_REUSEADDR, so the test can't hold it and hand it over.

func Window

func Window(t testing.TB, n int) int

Window returns the first port of n contiguous ports that can all be bound, scanning from a random port of the range.

Types

This section is empty.

Jump to

Keyboard shortcuts

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