timeouts-and-async
Fungsinya
Skill ini menjelaskan cara mencegah tes Ginkgo berjalan terlalu lama dan cara menguji pekerjaan latar belakang atau yang tertunda. Skill ini ditujukan untuk pengembang yang tes Go-nya macet atau berperilaku tidak konsisten.
Kapan dipakai
- βSaat tes Ginkgo macet atau berjalan melewati batas waktunya.
- βSaat Anda perlu memeriksa hasil yang membutuhkan waktu untuk muncul.
- βSaat kode tes berjalan di goroutine dan kegagalannya tidak dilaporkan.
Link skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/timeouts-and-async/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTes Go saya macet selamanya saat berbicara dengan worker latar belakang. Bagaimana cara membuatnya berhenti setelah beberapa detik?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menunjukkan cara memberi batas waktu pada tes, meneruskan sinyal pembatalan ke kode tes, dan menunggu hasil dengan pemeriksaan yang terus mencoba ulang.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Bagaimana cara memberi batas waktu untuk satu tes?
Skill menunjukkan cara menambahkan opsi timeout ke tes agar berhenti setelah waktu tertentu.
Apa arti pembatalan di sini?
Artinya tes diberi tahu untuk berhenti lebih awal, sehingga kode yang dipanggilnya bisa selesai dengan rapi.
Apa itu Eventually di Gomega?
Itu adalah pemeriksaan yang terus mencoba selama beberapa waktu sampai hasilnya menjadi benar.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 9.1k
- Peringkat
- #12309
- Lisensi
- MIT
- Diperbarui
- 9/10/2026
Komentar
- β¦
Skill lain dari repositori ini
ci
9.1kMembantu agent Anda menyiapkan tes Ginkgo untuk integrasi berkelanjutan, dengan flag yang direkomendasikan untuk menangkap penanda fokus atau tertunda yang tertinggal serta tes yang tidak stabil.
debugging-failures
9.1kMembantu agent Anda mencari tahu mengapa tes Ginkgo gagal dengan membaca baris ringkasan dan mengambil tes yang gagal beserta pesannya dari laporan JSON.
decorators
9.1kMembantu agent Anda memakai dekorator tes Ginkgo dengan benar, seperti Serial, Ordered, Label, Focus, dan batas waktu, dengan menjelaskan fungsi masing-masing.
filtering
9.1kMembantu agent Anda menjalankan hanya sebagian tes Ginkgo, memakai pending, skip, focus, label, batasan versi, dan filter file sesuai urutan prioritasnya.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.