timeouts-and-async
Ce qu’il fait
Ce skill explique comment empêcher des tests Ginkgo de durer trop longtemps, et comment tester un travail en arrière-plan ou différé. Il s'adresse aux développeurs dont les tests Go bloquent ou se comportent de façon incohérente.
Quand l’utiliser
- ✓Quand un test Ginkgo bloque ou dépasse sa limite de temps.
- ✓Lorsque vous devez vérifier un résultat qui met un certain temps à apparaître.
- ✓Quand le code de test s'exécute dans des goroutines et qu'un échec n'est pas signalé.
Lien du skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/timeouts-and-async/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Mon test Go reste bloqué indéfiniment quand il communique avec un worker en arrière-plan. Comment le faire arrêter après quelques secondes ?”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Le skill montre comment fixer des limites de temps aux tests, transmettre un signal d'annulation au code testé et attendre les résultats avec des vérifications qui réessaient jusqu'à réussir.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Comment fixer une limite de temps pour un seul test ?
Le skill montre comment ajouter une option de délai au test pour qu'il s'arrête après une durée donnée.
Que signifie l'annulation ici ?
Cela signifie que le test est invité à s'arrêter plus tôt, afin que le code qu'il appelle puisse se terminer proprement.
Qu'est-ce que Eventually dans Gomega ?
C'est une vérification qui continue de réessayer pendant un certain temps jusqu'à ce qu'un résultat devienne vrai.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 9.1k
- Position au classement
- #12309
- Licence
- MIT
- Mis à jour
- 09/10/2026
Commentaires
- …
Autres skills de ce dépôt
ci
9.1kAide votre agent à configurer les tests Ginkgo pour l'intégration continue, avec des options qui détectent les marqueurs oubliés et les tests instables.
debugging-failures
9.1kAide votre agent à comprendre pourquoi des tests Ginkgo ont échoué, en lisant le résumé et en extrayant les tests et messages exacts d'un rapport JSON.
decorators
9.1kAide votre agent à utiliser correctement les décorateurs de tests Ginkgo, comme Serial, Ordered, Label, Focus et les délais, en expliquant le rôle de chacun.
filtering
9.1kAide votre agent à lancer une partie des tests Ginkgo avec pending, skip, focus, labels et filtres, dans le bon ordre de priorité.
Skills similaires
test-driven-development
311kApprend à votre agent à écrire d'abord un test qui échoue, à le voir échouer, puis à écrire le code minimal qui le fait réussir, avant de construire toute fonctionnalité ou correction.
verification-before-completion
311kApprend à votre agent à lancer de véritables contrôles et à lire leurs résultats avant d'affirmer qu'une tâche, une correction ou une compilation est terminée ou réussie.
migrate-to-shoehorn
310kRemplace les conversions de type risquées dans vos fichiers de test par la bibliothèque shoehorn, afin que les tests utilisent des données partielles et passent les contrôles de types.