Documentation
¶
Overview ¶
Package testing implements helpers for gonnect interfaces implementations testing
Index ¶
- func RunNetworkErrorComplianceTests(t *testing.T, makeNetwork func() Network)
- func RunSimpleHTTPForNetworks(t *testing.T, a, b NetAddrPair)
- func RunSimpleHTTPTest(t *testing.T, ln net.Listener, dial gonnect.Dial)
- func RunStoppableNetworkTests(t *testing.T, makeNet func() UpDownNetwork, safeAddr string)
- func RunTCPPingPongTest(t *testing.T, ln net.Listener, dial DialFunc)
- func RunTcpPingPongForNetworks(t *testing.T, a, b NetAddrPair)
- func RunUDPPingPongTest(t *testing.T, pc gonnect.PacketConn, dial DialPacketFunc, numClients int, ...)
- func RunUdpPingPongForNetworks(t *testing.T, a, b NetAddrPair)
- type DialFunc
- type DialPacketFunc
- type NetAddrPair
- type Network
- type UpDownNetwork
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunNetworkErrorComplianceTests ¶
RunNetworkErrorComplianceTests runs a set of subtests against a Network implementation. supply `makeNetwork` that returns a fresh Network instance for testing.
func RunSimpleHTTPForNetworks ¶
func RunSimpleHTTPForNetworks(t *testing.T, a, b NetAddrPair)
func RunSimpleHTTPTest ¶
RunSimpleHTTPTest runs a very small HTTP client-server test over net.Conn. - ln: the net.Listener (server side) - dial: function to create a client net.Conn connected to ln.Addr()
func RunStoppableNetworkTests ¶
func RunStoppableNetworkTests( t *testing.T, makeNet func() UpDownNetwork, safeAddr string, )
RunStoppableNetworkTests verify that all Dial/Listen/Lookup operation fails for down networks.
func RunTCPPingPongTest ¶
RunTCPPingPongTest runs a ping-pong TCP test using the provided listener and dial function.
Protocol:
- Client sends "ping 0\n"
- Server reads "ping 0" and writes "pong 0\n"
- Client reads "pong 0" and writes "ping 1\n"
- ... repeat up to "ping 9" / "pong 9"
- After receiving "pong 9" client closes connection
- Server then performs one more Read and the test asserts that the error equals io.EOF
Notes:
- The function fails the test (t.Fatalf) on any mismatch, corruption, or unexpected error.
- The listener is NOT closed by this helper (caller should close when appropriate).
func RunTcpPingPongForNetworks ¶
func RunTcpPingPongForNetworks(t *testing.T, a, b NetAddrPair)
func RunUDPPingPongTest ¶
func RunUDPPingPongTest( t *testing.T, pc gonnect.PacketConn, dial DialPacketFunc, numClients int, rounds int, clientTimeout time.Duration, roundDelay time.Duration, maxRetries int, dropEvery int, testTimeout time.Duration, )
RunUDPPingPongTest runs a ping-pong test over PacketConn (UDP-like semantics). Client will use a single connected PacketConn and prefer Write/Read. If the returned PacketConn doesn't support Write/Read, the helper will fall back to WriteTo/ReadFrom.
Protocol summary:
- Client and server exchange "ping <n>\n" / "pong <n>\n" for n = 0..9.
- For each ping n the client will resend the same ping up to maxAttempts times (default 30) until it receives a matching "pong n".
- Server ignores out-of-order pings (seq > expected) and resends pongs for duplicates.
func RunUdpPingPongForNetworks ¶
func RunUdpPingPongForNetworks(t *testing.T, a, b NetAddrPair)
Types ¶
type DialPacketFunc ¶
type DialPacketFunc func(addr net.Addr) (gonnect.PacketConn, error)
DialPacketFunc dials to the given listener address and returns a net.PacketConn. The returned PacketConn should ideally be connected to the server address (so Write/Read work).