Pular para o conteúdo
Skillpedia
Testes9,1 mil · #12302

ordering-and-flakes

O que ela faz

Esta skill explica como rodar testes Ginkgo em uma ordem fixa e como lidar com testes que às vezes falham. É para desenvolvedores que escrevem testes em Go com o framework Ginkgo.

Quando usar

  • ✓Quando um conjunto de testes em Go precisa rodar em uma ordem fixa.
  • ✓Quando um teste Ginkgo falha só às vezes e precisa ser verificado ou repetido.
  • ✓Quando você quer encontrar testes que dependem da ordem em que rodam.

Link da skill

https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/ordering-and-flakes/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/ordering-and-flakes/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Nossos testes em Go falham de forma aleatória. Você consegue fazer os instáveis rodarem de forma confiável no Ginkgo?”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

Mostra quais configurações do Ginkgo forçam os testes a rodar um depois do outro e quais repetem ou tentam de novo um teste para expor comportamento instável.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

Ordering and flakes

Two topics that share a root cause: specs that aren't truly independent (ginkgo:overview). Ordering decorators let you declare a dependency on purpose; flake controls let you manage or expose one. Docs: https://onsi.github.io/ginkgo/#serial-specs, https://onsi.github.io/ginkgo/#ordered-containers, https://onsi.github.io/ginkgo/#repeating-spec-runs-and-managing-flaky-specs.

Serial: opt out of parallelism

Serial (container or subject) guarantees a spec never runs in parallel with anything else. Under the hood Ginkgo runs serial specs last, on process #1, after every other process has finished its suite. Reach for it sparingly. OK for benchmarks, resource hogs, or specs that put an external resource into a known-bad state - but not OK as a band-aid for order-dependence or poorly isolated code/specs.

Describe("Something expensive", Serial, func() {
	It("is a resource hog that can't share the box", func() { ... })
})

→ ginkgo:decorators, ginkgo:parallelism.

Ordered: run specs in definition order

Ordered (container only) guarantees its child specs run sequentially, in written order, on one process — so they may legitimately mutate shared closure state. They can still parallelize against specs in other containers; only the inner order is pinned.

Describe("checking out a book", Ordered, func() {
	var libraryClient *library.Client
	var book *books.Book

	BeforeAll(func() {                         // once, before the first spec
		libraryClient = library.NewClient()
		Expect(libraryClient.Connect()).To(Succeed())
		DeferCleanup(libraryClient.Disconnect) // context-aware: behaves like AfterAll
		DeferOnFailure(libraryClient.DumpState) // covers EVERY spec in this container; runs before teardown
	})

	It("can fetch a book", func() { book, _ = libraryClient.FetchByTitle("Les Miserables") })
	It("can check it out", func() { Expect(library.CheckOut(book)).To(Succeed()) })
	It("is then out of stock", func() { ... })

	AfterAll(func() { ... })                   // once, after the last spec
})
  • BeforeAll/AfterAll are legal only inside an Ordered container (or a container nested within one). That's the whole point of Ordered — once-per-group expensive setup.
  • A failing spec skips the rest of the group by default (then AfterAll still runs). Spec independence is gone, so Ginkgo won't pretend the later specs are meaningful.
  • ContinueOnFailure (outermost Ordered only — error on a nested container) overrides that: keep running later specs after a failure. Use it when Ordered is just shared setup, not a dependent flow. A failed BeforeAll still skips everything — the setup is presumed broken.
  • Nested containers inside an Ordered container are automatically Ordered; there's no way to un-order them.

OncePerOrdered: outer *Each setup that respects groups

A top-level BeforeEach that resets state runs before every spec — which breaks an Ordered group's first-spec-sets-up-rest contract (spec 1 passes, the rest get wiped). Decorate it with OncePerOrdered so it runs once per independent unit: still per-spec for normal specs, but once around each Ordered container (like a BeforeAll).

BeforeEach(OncePerOrdered, func() {
	libraryClient = library.NewClient()
	snapshot := libraryClient.TakeSnapshot()
	DeferCleanup(libraryClient.RestoreSnapshot, snapshot)
})

Applies to BeforeEach/JustBeforeEach/AfterEach/JustAfterEach only — not ReportBeforeEach/ReportAfterEach (reporting is always per-spec).

The Serial-inside-Ordered gotcha

You cannot mark an individual spec inside an Ordered container Serial. To make a whole ordered group run serially, put both decorators on the container: Describe("...", Ordered, Serial, func(){...}).

Ordered vs one big It

Ordered and a single It with By steps (ginkgo:writing-specs) solve the same "dependent flow" problem. Prefer one It + By by default — it stays fully parallelizable and independent. Reach for Ordered when you want each step reported as its own spec, or genuinely need BeforeAll once-per-group setup. Either way, use Ordered only when needed — it gives up internal parallelism.

SpecPriority

SpecPriority(int) (default 0, higher runs earlier, may be negative) is a scheduling hint — e.g. "boulders first, then sand" in big suites. Honored per-spec under --randomize-all, otherwise per outermost

Perguntas frequentes

Isso muda a velocidade dos meus testes?

Rodar os testes em ordem fixa ou um de cada vez pode deixá-los mais lentos, porque não podem rodar todos ao mesmo tempo.

Preciso saber Go para usar isso?

Sim. A skill trata de testes em Go, então você precisa de um projeto Go que use Ginkgo.

Ela ajuda a achar testes que dependem uns dos outros?

Sim. Ela descreve como repetir execuções e verificar dependência de ordem nos testes.

Detalhes

Descrição original do autor

Control spec ordering and manage flaky specs — Serial, Ordered containers with BeforeAll/AfterAll/ContinueOnFailure, OncePerOrdered, SpecPriority, plus FlakeAttempts/--flake-attempts, MustPassRepeatedly, --repeat, and --until-it-fails. Use when specs must run in a fixed order, you need once-per-group setup, you're combining Serial+Ordered, a spec is flaky, or you want to hunt order-dependence with --until-it-fails -p --randomize-all.

repo: onsi/ginkgo

Popularidade

Estrelas no GitHub
9,1 mil
Posição no ranking
#12302
Licença
MIT
Atualizada em
09/10/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas