// cleanupErr creates a cause when canceling a context because the test has completed. // It is a context.Canceled error. func cleanupErr(testName string) error { … } type canceledError … func (c canceledError) Error() string { … } func (c canceledError) Is(target error) bool { … } // withTimeout corresponds to [context.WithTimeout]. In contrast to // [context.WithTimeout], it automatically cancels during test cleanup, provides // the given cause when the deadline is reached, and its cancel function // requires a cause. func withTimeout(ctx context.Context, tb TB, timeout time.Duration, timeoutCause string) (context.Context, func(cause string)) { … } type deadlineContext … func (d deadlineContext) Deadline() (time.Time, bool) { … }