Documentation
¶
Overview ¶
Package testcase는 Go test가 case마다 쓰는 진행 보고 형식과 case별 기한이다.
모든 case는 실행하는 동안 다음 줄을 stdout에 출력한다.
RUN <case> deadline=<기한> STEP <case> elapsed=<경과>: <단계> PASS <case> elapsed=<경과> FAIL <case> elapsed=<경과>: <이유> SKIP <case> elapsed=<경과>
여러 case를 묶는 test는 자기 기한 없이 "RUN <group> group"으로 시작하고, 묶인 case가 저마다 기한을 가진다. runner의 장기 작업(build, 설치, 도구 실행)은 RunLong으로 기한 없이 "RUN <작업> no-deadline"으로 시작한다. 기한은 wall-clock 시간이다. 멈춘 case를 끝내는 timer이고 case 자신의 계산 시간을 재는 제한이 아니기 때문이다(AGENTS.md testing rule).
Index ¶
- Constants
- func Group(t testing.TB)
- func Run(name string, deadline time.Duration, work func(c *Case) error) error
- func RunLong(name string, work func(c *Case) error) error
- func StallGuard(parent context.Context, limit time.Duration) (ctx context.Context, progress func(), stop func())
- func StepBudget(steps int) time.Duration
- func Warn(format string, args ...any)
- type Case
- type StepWriter
Constants ¶
const ( // Compute는 memory 안의 계산과 repository file 읽기만 하는 case의 기한이다. 기준: // 이런 case 가운데 가장 큰 것(dbspec stress 문서의 parse와 emit, fuzz seed corpus)이 // 몇 초 안에 끝나므로, 1분을 넘긴 case는 멈춘 것이다. Compute = time.Minute // Database는 TEST_ENV의 database에 연결해 정해진 수의 statement를 실행하는 case의 // 기한이다. 기준: 이런 case는 database를 만들고 지우는 일을 포함해 수백 개 이하의 // statement를 실행하고, 공유 server에서 lock을 기다리는 시간까지 2분이면 넉넉하다. Database = 2 * time.Minute // Process는 `go build`, `go run`, php, node, Rust binary 같은 하위 process를 실행하는 // case의 기한이다. 기준: `go run`과 `go build`는 build cache가 비었을 때 package와 // 의존성을 다시 compile하는 데 몇 분이 걸린다. Process = 5 * time.Minute )
기한의 등급이다. case는 자기가 하는 일에 맞는 등급을 쓰고, 등급보다 오래 걸리는 일은 그 기준을 주석에 밝힌 자기 기한을 쓴다.
const Grace = 5 * time.Second
Grace는 deadline이 지난 뒤 process를 끝내기까지 기다리는 시간이다. Context를 따르는 case는 deadline에 자기 error로 실패하고 정리를 마칠 수 있고, Context를 따르지 않고 멈춘 case만 Grace 뒤에 끝난다.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run은 test가 아닌 runner(check 명령)가 case 하나를 같은 형식으로 실행하고 보고한다. work는 c.Context()를 따라야 한다. deadline에 Grace를 더한 시간이 지나도 work가 돌아오지 않으면 FAIL 줄을 출력하고 error를 돌려준다. work의 error는 FAIL 줄의 이유가 된다.
func RunLong ¶
RunLong은 test가 아닌 runner가 장기 작업 하나(build, 설치, 도구 실행)를 기한 없이 실행하고 "RUN <name> no-deadline", 단계, PASS나 FAIL과 경과 시간을 보고한다. 느리지만 정상인 작업이 시계 때문에 실패하지 않도록 timer를 두지 않는다. 성공과 실패는 work가 관측한 결과(명령의 종료 코드와 오류)로 정한다. c.Context()는 끝나지 않는다.
func StallGuard ¶
func StallGuard(parent context.Context, limit time.Duration) (ctx context.Context, progress func(), stop func())
StallGuard returns a context that is canceled, with a cause that names the limit, when progress is not called within limit. progress restarts the limit; stop releases the guard.
func StepBudget ¶
StepBudget is the deadline of a case that does the given number of steps one after another.
Types ¶
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case는 실행 중인 case 하나다.
func Of ¶
Of는 t에 Start한 case나, 없으면 t를 감싼 가장 가까운 test에 Start한 case다. case 값을 받지 않는 helper가 자기 단계를 그 case의 STEP 줄로 보고할 때 쓴다. 시작한 case가 없으면 t를 실패시킨다.
func Start ¶
Start는 t를 deadline 아래의 case로 시작하고 RUN 줄을 출력한다. t가 끝나면 PASS, FAIL, SKIP 줄을 경과 시간과 함께 출력한다. Context는 deadline에 끝난다. deadline에 Grace를 더한 시간이 지나도 끝나지 않으면 FAIL 줄과 모든 goroutine의 stack을 출력하고 test binary를 끝낸다. 멈춘 case는 스스로 돌아오지 않기 때문이다.
func (*Case) StepWriter ¶
func (c *Case) StepWriter() *StepWriter
StepWriter는 c의 단계로 줄을 출력하는 writer를 돌려준다.
type StepWriter ¶
type StepWriter struct {
// contains filtered or unexported fields
}
StepWriter는 쓰인 줄 가운데 빈 줄이 아닌 줄마다 Step 줄 하나를 출력하는 writer다. build 같은 하위 process의 진행 출력을 case의 단계로 보인다. process가 끝나면 Flush가 끝 줄을 출력한다.