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 ¶
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:
- Seq runs from 1 with no gaps. Every span starts once and ends once, and no span id is zero or used twice.
- 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.
- 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.
- No more targets run at once below a span than its Limit.
- Every Suspend is followed by one Resume.
- No text holds anything termtext.EscapeCell would escape, and none is longer than its bound. Hidden and ShowLines are passed down.
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 ¶
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) Tree ¶
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.
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.