timeouts-and-async
Was er macht
Dieser Skill erklärt, wie du verhinderst, dass Ginkgo-Tests zu lange laufen, und wie du Hintergrund- oder verzögerte Arbeit testest. Er richtet sich an Entwickler, deren Go-Tests hängen oder sich unberechenbar verhalten.
Wann du ihn nutzt
- ✓Wenn ein Ginkgo-Test hängt oder sein Zeitlimit überschreitet.
- ✓Wenn du ein Ergebnis prüfen musst, das eine Weile braucht, bis es erscheint.
- ✓Wenn Testcode in Goroutinen läuft und ein Fehler nicht gemeldet wird.
Link zum Skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/timeouts-and-async/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Mein Go-Test hängt ewig, wenn er mit einem Hintergrund-Worker spricht. Wie bringe ich ihn dazu, nach ein paar Sekunden abzubrechen?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Er zeigt, wie du Zeitlimits für Tests setzt, ein Abbruchsignal in den Testcode gibst und auf Ergebnisse mit wiederholten Prüfungen wartest.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen
Wie setze ich ein Zeitlimit für einen Test?
Der Skill zeigt, wie du eine Timeout-Option hinzufügst, damit der Test nach einer festen Zeit stoppt.
Was bedeutet Abbruch hier?
Der Test wird angewiesen, früh aufzuhören, damit der aufgerufene Code sauber enden kann.
Was ist Eventually in Gomega?
Das ist eine Prüfung, die eine Weile immer wieder versucht, bis ein Ergebnis zutrifft.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 9.1k
- Platz im Ranking
- #12309
- Lizenz
- MIT
- Aktualisiert
- 9.10.2026
Kommentare
- …
Weitere Skills aus diesem Repository
ci
9.1kHilft deinem Agenten, Ginkgo-Tests für CI einzurichten, mit empfohlenen Flags, die vergessene Fokus- und Pending-Markierungen sowie instabile Tests aufdecken.
debugging-failures
9.1kHilft deinem Agenten herauszufinden, warum Ginkgo-Tests fehlgeschlagen sind, indem er die Zusammenfassungszeile liest und die genauen Fehler aus einem JSON-Bericht holt.
decorators
9.1kHilft deinem Agenten, Ginkgo-Test-Dekoratoren richtig einzusetzen, etwa Serial, Ordered, Label, Focus und Timeouts, indem er erklärt, was jeder bewirkt.
filtering
9.1kHilft deinem Agenten, nur einen Teil der Ginkgo-Tests auszuführen, mit Pending, Skip, Focus, Labels, Versionsbedingungen und Dateifiltern in der richtigen Rangfolge.
Ähnliche Skills
test-driven-development
311kBringt deinem Agenten bei, vor jedem Feature oder Fix zuerst einen fehlschlagenden Test zu schreiben, ihn fehlschlagen zu sehen und dann den kleinsten passenden Code zu schreiben.
verification-before-completion
311kBringt deinem Agenten bei, echte Prüfungen auszuführen und ihre Ausgabe zu lesen, bevor er behauptet, eine Aufgabe, ein Fix oder ein Build sei fertig oder bestehe.
migrate-to-shoehorn
310kErsetzt riskante Typumwandlungen in deinen Testdateien durch die Bibliothek shoehorn, damit Tests mit unvollständigen Daten arbeiten und trotzdem die Typprüfung bestehen.