testbudget

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testbudget is the measured half of forge's fast/slow test tiers: it reads a `go test -short -json` run and reports every test that took longer than the budget.

Under -short a test marked slow (forge/pkg/testkit.Slow, or an `if testing.Short() { t.Skip(...) }` guard) skips, so every test that RAN in a -short run is, by construction, one that claims to be fast. One that took longer than the budget is a slow test nobody marked: it is making the blocking tier slow for everyone. The static half (internal/linter/slowtest) flags slow work it can recognize in source; this catches whatever makes a test slow, after it ran slowly once.

Only top-level tests are judged. That is where the marker goes, and a parent's elapsed time includes its subtests', so a table whose cases are each quick but sum past the budget is still reported — it is still that long in the blocking tier. A t.Parallel test's paused time is excluded by the testing package itself.

Index

Constants

View Source
const DefaultBudget = 2 * time.Second

DefaultBudget is the longest a test may take in the fast tier.

Variables

View Source
var ErrNoInput = errors.New("no go test -json events in the input")

ErrNoInput is returned when the stream held no `go test -json` events.

Functions

func Locate

func Locate(rep *Report, moduleRoot string)

Locate fills each overrun's File, Line and Marked from the module rooted at moduleRoot. A package outside that module, or a test it cannot find, is left unlocated: the report still names the package and the test.

Types

type Overrun

type Overrun struct {
	Package string
	Test    string
	Elapsed time.Duration
	// File and Line locate the test's declaration (File relative to the
	// module root), when Locate could resolve it.
	File string
	Line int
	// Marked reports that the declaration calls testing.Short or
	// testkit.Slow in its own body. A marked test that ran over budget is
	// either still slow under -short, or the run was not made with -short.
	Marked bool
}

Overrun is one top-level test that took longer than the budget.

type Report

type Report struct {
	Budget time.Duration
	// Ran counts the top-level tests that ran (passed or failed).
	Ran int
	// Overruns are the tests over budget, slowest first.
	Overruns []Overrun
	// FailedPackages names the packages that failed or did not build. A
	// budget check is no verdict on a red run: `go test -json | forge ...`
	// reports only forge's status unless the shell sets pipefail.
	FailedPackages []string
}

Report is a judged run.

func Check

func Check(r io.Reader, budget time.Duration) (Report, error)

Check reads a `go test -json` stream and judges it against budget.

Jump to

Keyboard shortcuts

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