loadtest

package
v0.0.0-...-186a9b1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 18 Imported by: 1 module, 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 simulates players that connect to a triebwerk server over a websocket or WebTransport, drive around with random human like inputs, shoot and ping. It records what every player receives so a run can be checked against expectations (see Report.Check). Used by cmd/loadtest and by the load test in the game package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Name string
	// contains filtered or unexported fields
}

Bot is one simulated player

func (*Bot) Keys

func (b *Bot) Keys() (int, []byte)

Keys returns the player id on the server and the currently pressed keys

func (*Bot) Report

func (b *Bot) Report() BotReport

Report returns a copy of what the bot has seen so far

type BotReport

type BotReport struct {
	Name string
	// player ids the server assigned, one per connection
	PlayerIDs       []int
	LostConnections int
	RoundsStarted   int
	RoundsEnded     int
	StateMessages   int
	// time between the first and the last state broadcast of every round,
	// summed up, used to compute the update rate
	ActiveTime time.Duration
	// longest gap between two state broadcasts within a round
	MaxGap time.Duration
	// most player entries in one state broadcast
	MaxPlayersSeen int
	// player ids that appeared twice in one broadcast
	DuplicateIDs int
	// own deaths and shots as reported by the server
	Deaths int
	Shots  int
	// scoreboards and kill events the server sent, and messages of those
	// kinds that did not have the agreed layout
	Scoreboards int
	Kills       int
	BadMessages int
	// answers to pings
	Pongs int
	// inputs sent, the number of the last one the server applied, snapshots
	// that came after the server had the first input and those among them
	// for which no input had arrived in time
	InputsSent   int
	LastAck      uint32
	Acknowledged int
	Starved      int
	// contains filtered or unexported fields
}

BotReport is what one simulated player saw during a run

func (BotReport) StarvedShare

func (r BotReport) StarvedShare() float64

StarvedShare is the share of ticks for which the server had no input of this player

func (BotReport) UpdateRate

func (r BotReport) UpdateRate() float64

UpdateRate is the number of state broadcasts per second during rounds

type Config

type Config struct {
	// Address of the server: ws://localhost:9090/echo for its websocket
	// (wss:// with TLS), https://localhost:9090/wt for WebTransport. The
	// certificate is not checked, the bots are a test tool.
	URL     string
	Players int
	// number of the first player's name (load-00), for two runs against one server
	FirstName int
	// Tokens of accounts on the master server: the first players say hello
	// with one each and play as that account, the others are guests
	Tokens []string
	// how long every player stays, 0 runs until the context is cancelled
	Duration time.Duration
	// players that leave once after ReconnectAfter and rejoin 5 seconds later
	Reconnect      int
	ReconnectAfter time.Duration
	// players join at a random time within this window, default 3s
	Stagger time.Duration
	// OneKind makes every player drive the first kind of tank. By default
	// the players take the kinds in turn, each in one of its paint jobs.
	OneKind bool

	// optional hooks, called from the bot goroutines: every snapshot a bot
	// receives, and "start" and "end" of rounds with the tick they happened at
	OnState func(snapshot protocol.SnapshotMessage)
	OnEvent func(event string, tick uint32)
	// progress output, default log.Printf, set to a no-op to silence
	Logf func(format string, args ...interface{})
	// how often progress is logged, 0 disables it
	LogInterval time.Duration
}

Config of a load test run

type Expectations

type Expectations struct {
	// Scoreboard: every player has to receive names and scores
	Scoreboard bool
	// all of them in one match at the same time
	Players int
	// rounds every player has seen end
	MinRounds int
	// longest allowed pause between two state broadcasts within a round
	MaxGap time.Duration
	// state broadcasts per second every player has to receive, the server ticks at 30
	MinUpdateRate float64
	// Inputs: the server has to apply the inputs of every player and answer its pings
	Inputs bool
	// largest share of ticks for which a player's input may come too late
	MaxStarvedShare float64
}

Expectations a healthy server has to meet, zero values are not checked

func DefaultExpectations

func DefaultExpectations(players int) Expectations

DefaultExpectations for a run with the given number of players

type Report

type Report struct {
	Duration time.Duration
	Bots     []BotReport
}

Report of a whole run

func (Report) Check

func (r Report) Check(e Expectations) []error

Check returns every violated expectation, nil if the run was healthy

func (Report) String

func (r Report) String() string

String is a table of the run, one row per player

type Runner

type Runner struct {
	Config Config
	Stats  *Stats
	Bots   []*Bot
}

Runner holds the bots of one run so they can be observed while it runs

func NewRunner

func NewRunner(cfg Config) *Runner

NewRunner creates the bots, nothing connects before Run

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) Report

Run plays until the duration is over or the context is cancelled and returns what every player has seen

type Stats

type Stats struct {
	Connected       int64
	StateMessages   int64
	LostConnections int64
	// contains filtered or unexported fields
}

Stats are live counters shared by all bots of a run

func (*Stats) TakeMaxGap

func (s *Stats) TakeMaxGap() time.Duration

TakeMaxGap returns the longest gap since the last call and resets it

Jump to

Keyboard shortcuts

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