loadtest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 7 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 loadtest drives many WebSocket clients at a server, some of which stop reading, and counts what each one saw. The load tests in http/ and the observable_relay exercise (cmd/grpcws-demo -exercise) both use it.

It speaks plain WebSocket and imports nothing from servicekit, so tests inside package http can use it without an import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn *websocket.Conn

	// Stuck clients never read. Once their TCP window fills, the server's
	// writes to them block, which is what WriteTimeout exists for.
	Stuck bool
	// contains filtered or unexported fields
}

Client is one connection in a Pool.

func (*Client) Ended

func (c *Client) Ended() <-chan struct{}

Ended is closed when the client's read loop stops, because the server closed the connection or Pool.Close did. It is never closed for a stuck client, which has no read loop.

func (*Client) Received

func (c *Client) Received() int64

Received is how many data frames this client has read (those that pass Options.Count, if set).

func (*Client) ServerClosed

func (c *Client) ServerClosed() bool

ServerClosed reports whether the server ended this reader's connection, as opposed to Pool.Close or a network error.

type Options

type Options struct {
	// Clients is how many connections to open, and Stuck how many of those
	// (the last ones) never read.
	Clients, Stuck int

	// First, if set, is written by every client right after it connects
	// (a grpcws request, a join message).
	First []byte

	// URLFor, if set, gives client i its own URL (a player id in the
	// query, say) instead of the one passed to Dial.
	URLFor func(i int) string

	// Count, if set, picks which frames Received counts. Nil counts all.
	Count func(frame []byte) bool

	// Parallel bounds concurrent dials. Zero means 32, which stays under
	// the default listen backlog on macOS.
	Parallel int

	Dialer *websocket.Dialer
}

Options configures Dial.

type Pool

type Pool struct {
	Clients []*Client
}

Pool is a set of clients dialled together.

func Dial

func Dial(ctx context.Context, url string, opts Options) (*Pool, error)

Dial opens the pool. On any dial error it closes what it opened and returns the error.

func (*Pool) Close

func (p *Pool) Close()

Close closes every client: readers send a normal close frame and wait briefly for the server's answer, stuck clients just drop the socket.

func (*Pool) Readers

func (p *Pool) Readers() []*Client

Readers returns the clients that read.

func (*Pool) Received

func (p *Pool) Received() int64

Received is the total data frames read across the pool.

func (*Pool) SendAll

func (p *Pool) SendAll(msg []byte, times int, skipStuck bool) error

SendAll writes msg from every reader, times times. Stuck clients write too unless skipStuck, since a client that stops reading may still be sending.

func (*Pool) Slowest

func (p *Pool) Slowest() (int64, bool)

Slowest is the lowest Received among readers still connected, and false if none are.

func (*Pool) WaitEach

func (p *Pool) WaitEach(n int64, timeout time.Duration) error

WaitEach waits until every reader has read at least n frames.

Jump to

Keyboard shortcuts

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