timeouts-and-async
하는 일
이 스킬은 Ginkgo 테스트가 너무 오래 실행되는 것을 막는 방법과, 백그라운드나 지연된 작업을 테스트하는 방법을 설명합니다. Go 테스트가 멈추거나 일관되지 않게 동작하는 개발자를 위한 것입니다.
사용하는 경우
- ✓Ginkgo 테스트가 멈추거나 제한 시간을 넘길 때.
- ✓몇 초 뒤에 나타나는 결과를 확인해야 할 때.
- ✓테스트 코드가 고루틴에서 실행되고 실패가 보고되지 않을 때.
스킬 링크
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/timeouts-and-async/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 Go 테스트가 백그라운드 워커와 통신할 때 영원히 멈춥니다. 몇 초 뒤에 멈추게 하려면 어떻게 해야 하나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
이 스킬은 테스트에 제한 시간을 설정하고, 테스트 코드에 취소 신호를 전달하며, 결과가 나올 때까지 계속 다시 확인하는 검사로 기다리는 방법을 보여 줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Timeouts, interruptible nodes, and async testing
Builds on the failure mental model in ginkgo:overview (failure is a panic Ginkgo recovers; a goroutine that fails needs defer GinkgoRecover()). Docs: https://onsi.github.io/ginkgo/#spec-timeouts-and-interruptible-nodes and https://onsi.github.io/ginkgo/#patterns-for-asynchronous-testing.
Interruptible nodes: take a context, honor cancellation
A setup or subject node becomes interruptible simply by accepting a SpecContext (or plain context.Context) — Ginkgo supplies one automatically:
It("likes to sleep in", func(ctx context.Context) {
select {
case <-ctx.Done(): return // honor cancellation and exit promptly
case <-time.After(time.Hour): ...
}
}, NodeTimeout(time.Second))
On timeout or interrupt, Ginkgo cancels the context to tell the node to stop. Pass ctx down into every blocking call (libraryClient.SaveBook(ctx, book), exec.CommandContext(ctx, ...)) so the cancellation actually propagates. Only setup/subject nodes are interruptible — container nodes are not (they run at construction time).
ctx.Deadline()does NOT report the node's deadline. Ginkgo manages cancellation timing itself (to snapshot a progress report first), so it does not use aWithDeadlinecontext. Trust<-ctx.Done(), notDeadline().SpecContextsatisfiescontext.Context; you may wrap it (context.WithValue) and Ginkgo still cancels the result on time.
The timeout decorators (full reference → ginkgo:decorators)
| Decorator | Scope |
|---|---|
NodeTimeout(d) |
Deadline for one interruptible node. |
SpecTimeout(d) |
Deadline for the whole spec lifecycle — It only. |
GracePeriod(d) |
How long Ginkgo waits after cancelling before leaking the node. |
SpecTimeoutcan only be more lenient than a node'sNodeTimeout— it caps the sum of all nodes (BeforeEach+It+AfterEach); a per-nodeNodeTimeoutinside it is always more stringent.- Cleanup still runs after a timeout. When
SpecTimeoutfires, Ginkgo cancels the current node, runs anyDeferOnFailurecallbacks (not bound by the expiredSpecTimeout), then runsAfterEach/AfterAll/DeferCleanup(each under its ownNodeTimeout/grace). The timeout is a "mark failed" threshold, not a hard kill. - A node that ignores cancellation is "leaked," not killed. After the grace period Ginkgo gives up waiting and moves on. Leaking is deliberately preferred over hanging forever — but a leaked goroutine keeps running and can call
Fail/AddReportEntryand pollute a later spec. Always make blocking code respond toctx.Done(). DeferCleanup/DeferOnFailure/DescribeTableentries are interruptible too — give the cleanup/entry func actxfirst arg; don't capture and reuse the parent node'sctx(it's already cancelled by cleanup time).
Interrupting the whole suite
ginkgo --timeout=DURATION— suite-wide budget across all suites (default1h).Abort("reason")— end the suite immediately from within a spec (programmatic interrupt).SIGINT/SIGTERM(^C) — interrupt: cancel the current interruptible node, run its cleanup + reporting nodes, skip the rest, exit failed. Escalation: a 2nd interrupt skips cleanup (still runs reporting); a 3rd bails immediately. To inspect a suite without stopping it, sendSIGINFO/SIGUSR1for a progress report →ginkgo:debugging-failures.
Async assertions: Eventually / Consistently
Use Gomega's Eventually (polls until the matcher passes or it times out) and Consistently (polls and requires the matcher to hold the whole interval — the way to assert something doesn't happen). Three input shapes: bare values (channels, gbytes), functions returning (value[, error]), and functions taking a Gomega.
It("publishes a book", func(ctx SpecContext) {
buffer := gbytes.NewBuffer()
c := publisher.Publish(ctx, book, buffer) // pass ctx so it cancels cleanly
Eventually(ctx, buffer).Should(gbytes.Say(`Publish complete!`))
var result publisher.PublishResult
Eventually(ctx, c).WithTimeout(time.Second).Should(Receive(&result)) // poll, don't <-c
}, SpecTimeout(time.Second*30))
Propagate the spec deadline into the poll with .WithContext(ctx) or the positional Eventually(ctx, ...) — now a node timeout/interrupt makes the Eventually exit immediately instead of running its own clock. Gomega also **auto-injec
자주 묻는 질문
테스트 하나에 제한 시간을 어떻게 정하나요?
이 스킬은 테스트에 시간 제한 옵션을 추가해서 정해진 시간 뒤에 멈추게 하는 방법을 보여 줍니다.
여기서 취소는 무엇을 뜻하나요?
테스트가 일찍 멈추도록 신호를 받는다는 뜻이며, 그러면 호출하는 코드가 깔끔하게 끝날 수 있습니다.
Gomega의 Eventually는 무엇인가요?
결과가 참이 될 때까지 일정 시간 계속 시도하는 검사입니다.
상세 정보
작성자의 원본 설명
Make Ginkgo specs interruptible and test asynchronous behavior — SpecContext/context.Context cancellable nodes, NodeTimeout/SpecTimeout/GracePeriod, the --timeout flag, Abort and SIGINT behavior, Gomega Eventually/Consistently (the func(g Gomega) form, .WithContext), and the defer GinkgoRecover() rule for goroutines. Use when a spec hangs or times out, polls for eventual consistency, tests channels/streams/processes, launches goroutines, or needs a deadline.
repo: onsi/ginkgo
인기도
- GitHub 스타
- 9.1k
- 순위
- #12309
- 라이선스
- MIT
- 업데이트
- 2026. 10. 9.
댓글
- …
이 저장소의 다른 스킬
ci
9.1k에이전트가 지속적 통합에서 Ginkgo 테스트를 설정하도록 돕습니다. 남은 focus나 pending 표시와 불안정한 테스트를 잡아내는 권장 플래그를 씁니다.
debugging-failures
9.1k에이전트가 요약 줄을 읽고 JSON 보고서에서 실패한 정확한 테스트와 메시지를 꺼내서, Ginkgo 테스트가 왜 실패했는지 알아내도록 돕습니다.
decorators
9.1k에이전트가 Serial, Ordered, Label, Focus, 제한 시간 같은 Ginkgo 테스트 데코레이터를 바르게 쓰도록 각각의 역할을 설명해 돕습니다.
filtering
9.1k에이전트가 pending, skip, focus, 라벨, 버전 조건, 파일 필터를 올바른 우선순위에 따라 써서 Ginkgo 테스트의 일부만 실행하도록 돕습니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.