Documentation
¶
Overview ¶
Package freeport provides a helper for reserving free TCP ports across multiple processes on the same machine. Each process reserves a block of ports outside the ephemeral port range. Tests can request one of these reserved ports and freeport will ensure that no other test uses that port until it is returned to freeport.
Freeport is particularly useful when the code being tested does not accept a net.Listener. Any code that accepts a net.Listener (or uses net/http/httptest.Server) can use port 0 (ex: 127.0.0.1:0) to find an unused ephemeral port that will not conflict.
Any code that does not accept a net.Listener or can not bind directly to port zero should use freeport to find an unused port.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetN ¶
GetN returns n free ports from the reserved port block, and returns the ports to the pool when the test ends. See Take for more details.
func GetOne ¶
GetOne returns a single free port from the reserved port block, and returns the port to the pool when the test ends. See Take for more details. Use GetN if more than a single port is required.
func Return ¶
func Return(ports []int)
Return returns a block of ports back to the general pool. These ports should have been returned from a call to Take().
Types ¶
type TestingT ¶
type TestingT interface {
Cleanup(func())
Helper()
Fatalf(format string, args ...interface{})
Name() string
}
TestingT is the minimal set of methods implemented by *testing.T that are used by functions in freelist.
In the future new methods may be added to this interface, but those methods should always be implemented by *testing.T