testing

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: CC0-1.0 Imports: 16 Imported by: ? 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 testing implements helpers for gonnect interfaces implementations testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunNetworkErrorComplianceTests

func RunNetworkErrorComplianceTests(t *testing.T, makeNetwork func() Network)

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

func RunSimpleHTTPTest(t *testing.T, ln net.Listener, dial gonnect.Dial)

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

func RunTCPPingPongTest(t *testing.T, ln net.Listener, dial DialFunc)

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 = 1..rounds.
  • 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 DialFunc

type DialFunc func(addr net.Addr) (net.Conn, error)

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).

type NetAddrPair

type NetAddrPair struct {
	Network gonnect.Network
	Addr    string
}

type Network

type Network interface {
	gonnect.Network
}

type UpDownNetwork

type UpDownNetwork interface {
	gonnect.Network
	gonnect.Resolver
	gonnect.UpDown
}

Jump to

Keyboard shortcuts

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