progresstest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 12 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 progresstest captures the progress events of a test, draws them as a tree that does not depend on the order concurrent work happened in, and checks that they keep the promises the progress package makes to every sink.

Checked and Watch give a test a context with a Bus of its own. Both keep one rule: Check runs on the events as the work left them, before the Bus is closed, since Close would end a span the work left open as canceled and hide that it never ended. Checked runs it when the test ends; Watch when the test asks for the tree.

What Check holds an emitter to

A package that reports progress, a library's or a program's, keeps the promises Check lists. Three of them shape how work that runs in parallel is reported, and are the ones a pool written by hand most often breaks:

  • Every target of a Fold step or a batch, and every batch of a step, is announced queued, with progress.Queued, before the first of them runs. A pool that starts each target from its own goroutine as it takes its place, as errgroup.Go does, breaks this: start them all first, then run them; the pools of the fanout package do.
  • When a Fold step or a batch ends, the targets under it that ended are its Total, however they ended, so a counter always reaches its total; no count passes its Total, and a Total never shrinks.
  • No more targets run at once below a span than its Limit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t testing.TB, events []progress.Event)

Check reports, as errors of t, every promise the events break. Call it once the work is done, before the Bus is closed, so that a span the work left open is reported rather than ended by Close:

  1. Seq runs from 1 with no gaps. Every span starts once and ends once, and no span id is zero or used twice.
  2. A span starts under a parent that has started and not ended, and ends after every span under it. Its Run, Update and Line events come between its Start and its End, and a Run only follows a queued Start.
  3. The work a step knows of is announced up front. The targets of a Fold step or a batch, and the batches of a step, all start queued before the first of them runs. When a Fold step or a batch ends, its targets that ended, however they ended, are its Total; a batch or a Fold step that was skipped or canceled before any target of its own started counts as its Total. No count ever exceeds its Total, and no Total shrinks, so a counter never goes backwards and always reaches its total, even after an interrupt.
  4. No more targets run at once below a span than its Limit.
  5. Every Suspend is followed by one Resume.
  6. No text holds anything termtext.EscapeCell would escape, and none is longer than its bound. Hidden and ShowLines are passed down.

func Watch

func Watch(ctx context.Context, t testing.TB, opts ...Option) (context.Context, func() string)

Watch returns ctx with a Bus of its own, whose events a Capture keeps, and a function to call once the work is done: it runs Check on the events, closes the Bus and returns their Tree. The Capture asks for no lines.

Types

type Capture

type Capture struct {
	// Lines makes the capture ask for lines of output, as a live display
	// does, so that progress.Tee produces them.
	Lines bool
	// contains filtered or unexported fields
}

Capture is a sink that keeps every event it is sent. It is safe for concurrent use.

func Checked

func Checked(ctx context.Context, t testing.TB, opts ...Option) (context.Context, *Capture)

Checked returns ctx with a Bus of its own, whose events a Capture keeps and Check checks when the test ends, before the Bus is closed. The Capture asks for the lines of output, as a live display does, so that they are checked too; it is returned for a test that reads the events, or their Tree, while the work is under way.

func (*Capture) Events

func (c *Capture) Events() []progress.Event

Events returns a copy of the events kept so far.

func (*Capture) Handle

func (c *Capture) Handle(e progress.Event)

Handle keeps e.

func (*Capture) Tree

func (c *Capture) Tree() string

Tree draws the spans of the events kept so far, one line each, indented under their parent:

step reset the machines total=3 limit=8 [fold]: failed (target): 1 of 3 failed
  target exe[1-2]: ok
    call redfish method=POST path=/redfish/v1/Systems/1: ok
  target exe3: failed (transport): {}: no answer

Nothing in it depends on how concurrent work was scheduled. Targets that read the same once their own node and host are written {} are folded into one line naming them as a node set; siblings are sorted by what they read, with numbers in their numeric order; and neither ids, times nor lines of output are drawn. A span not ended reads as its state.

Tests compare trees whole, so the format is kept: a field is drawn only when it has a value, and a field added to progress.Fields is drawn after those drawn before it. Changing how an existing field is drawn changes what every such test compares.

func (*Capture) WantsLines

func (c *Capture) WantsLines() bool

WantsLines reports c.Lines.

type Option

type Option func(*progress.Options)

An Option sets up the Bus that Checked and Watch make.

func Classify

func Classify(fallback func(error) progress.Class) Option

Classify has the Bus class an error that says no class of its own by fallback, as progress.Options.Classify does, so that the events carry the classes the program's own Bus would give them.

type Screen

type Screen struct {
	// Width is the number of columns, at which a row wraps; 0 is a row
	// that never does.
	Width int
	// contains filtered or unexported fields
}

Screen is a terminal for a test to draw on and read back: it shows what is written to it the way a terminal would, as far as a display writes it. It knows text, a newline, which starts the next row at its first column as a terminal's output processing has it do, a carriage return, and the sequences ESC [ n A, which moves the cursor up n rows, ESC [ 2K, which erases the row the cursor is on, ESC [ K, which erases the rest of it, and ESC [ J, which erases from the cursor to the end of the screen. Any other control character or sequence is shown as text, "^[[?25l" or "^G", so that a test sees it.

Every row is kept, those that have scrolled off the top too, so that what a Screen shows is the scrollback and the screen in one. With Width set, a row wraps at that column, as a terminal's does, so that a row drawn too long shows as the two it is. A Screen is safe for concurrent use.

func (*Screen) String

func (s *Screen) String() string

String returns what the screen shows, each row ended by a newline, up to the last row that is not blank.

func (*Screen) Write

func (s *Screen) Write(p []byte) (int, error)

Write shows p on the screen.

Jump to

Keyboard shortcuts

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