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 ¶
Received is how many data frames this client has read (those that pass Options.Count, if set).
func (*Client) ServerClosed ¶
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 (*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) SendAll ¶
SendAll writes msg from every reader, times times. Stuck clients write too unless skipStuck, since a client that stops reading may still be sending.