Skip to content
Skillpedia
Testing9.1k Β· #12304

parallelism

What it does

This skill shows how to run Ginkgo tests on several processes at once to save time. It is for developers whose Go test suites take a long time to finish.

When to use it

  • βœ“When your Ginkgo test suite takes too long to run.
  • βœ“When you need tests to use many CPU cores at the same time.
  • βœ“When parallel tests share ports, folders or databases and need separate settings.

Skill link

https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/parallelism/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/parallelism/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œMy Go test suite takes too long, can you make it run in parallel with Ginkgo?”

5 new skills a week. 1 minute to read.

How it works

It runs several copies of the test program as separate processes, each taking its own share of tests, and then combines the results into one report.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Running Ginkgo in parallel

Parallelism is where Ginkgo's "every spec is independent" assumption (ginkgo:overview) earns its keep. If your specs are independent, going parallel is one flag. If they aren't, parallelism is how you find out. Docs: https://onsi.github.io/ginkgo/#spec-parallelization, https://onsi.github.io/ginkgo/#patterns-for-parallel-integration-specs.

The flag

ginkgo -p            # auto-detect optimal process count from CPU cores
ginkgo --procs=4     # pin the count explicitly
ginkgo watch -p      # re-run in parallel on every file change

-p/--procs require the ginkgo CLI β€” go test cannot parallelize a Ginkgo suite (it has no server to coordinate processes). Most other features work under go test; parallelism is the headline exception. β†’ ginkgo:running.

The mental model: separate processes, not goroutines

This is the one thing to internalize. Ginkgo compiles the suite once (go test -c), then launches N copies of the test binary as separate OS processes. Each process runs the full tree-construction phase independently (so all N build the identical spec list), then pulls specs to run from the CLI, which acts as a server and merges everything into one coherent output stream.

  • Separate processes means separate memory. Each process has its own copy of every package-level var and closure variable. There is no shared memory, so shared-closure specs like var book don't race across processes β€” they each get their own book. (Within a process specs still run one at a time.)
  • The flip side: a BeforeSuite runs on every process, so anything it creates is created N times.
  • You usually don't care which process runs a spec β€” except for the integration patterns below, which deliberately shard shared external resources by process index.

What the N processes cost

Going parallel is cheap, but not free β€” and the cost is rarely where people look for it.

  • Compilation is once per suite, not once per process. Ginkgo builds the test binary a single time and runs N copies of it; under -r the CLI also overlaps compiling the next suite with running the current one. It is usually not the bottleneck it's assumed to be.
  • Teardown is once per process β€” but they overlap, so a suite pays roughly one process teardown, not N.
  • Under --race that one teardown is ~1s. ThreadSanitizer sleeps for a second at process exit (atexit_sleep_ms, its default) so races reported by goroutines still running at exit aren't lost. Every process pays it however trivial the suite: a 2-spec package pays exactly what a 2000-spec package pays.

That flatness is the tell. The sleep lands in the gap between suites under -r, where it looks exactly like compilation β€” but a build cost can't be flat across package size, and a per-process cost must be. If you're auditing a slow -p --race run, precompile with ginkgo build -r so compilation is excluded by construction rather than by inference. To remove the sleep:

GORACE=atexit_sleep_ms=0 ginkgo -r -p --race

This slightly weakens detection at the very end of a suite β€” a reasonable trade when your races are found by your specs rather than at teardown, but a deliberate one; write the reason down where you set it. β†’ ginkgo:ci for the whole CI flag set.

Suite setup when N copies is wrong: Synchronized*Suite

BeforeSuite runs on every process β†’ N independent resources. Sometimes that's ideal (max isolation). When a resource is expensive or must be shared, use SynchronizedBeforeSuite: set it up once on process #1, then distribute connection info to all processes.

var dbClient *db.Client

var _ = SynchronizedBeforeSuite(func() []byte {
	// runs ONLY on process #1; all others wait
	dbRunner := db.NewRunner()
	Expect(dbRunner.Start()).To(Succeed())
	DeferCleanup(dbRunner.Stop)              // runs like SynchronizedAfterSuite: after ALL procs finish
	return []byte(dbRunner.Address())        // []byte passed to every process
}, func(address []byte) {
	// runs on ALL processes with the data from process #1
	dbClient = db.NewClient()
	Expect(dbClient.Connect(string(address))).To(Succeed())
	dbClient.SetNamespace(fmt.Sprintf("namespace-%d", GinkgoParallelProcess()))
	DeferOnFailure(dbClient.DumpNamespace)   // suite-wide failure diagnostics belong here (every process), not in the proc-#1 func
})
BeforeSuite SynchronizedBeforeSuite
process #1
FAQ

Does parallel running always make tests faster?

Usually, but starting each copy takes time, which can cancel out the gain for small suites.

Why can I not use go test for parallel runs?

The standard go test command cannot coordinate the separate processes, so the ginkgo command is needed.

What is the risk of running tests in parallel?

Tests that share a port or database can clash, so each process needs its own settings.

Details

Original description by the author

Run Ginkgo suites in parallel β€” ginkgo -p / --procs, the separate-process (not goroutine) model, SynchronizedBeforeSuite/SynchronizedAfterSuite vs BeforeSuite, GinkgoParallelProcess() for sharding ports/tmpdirs/databases, building a binary once via gexec, piping child-process output to GinkgoWriter, and what N processes actually cost (compilation vs teardown, and the fixed ~1s --race adds per suite β€” GORACE=atexit_sleep_ms=0). Use when parallelizing a suite, speeding up integration tests, auditing why a parallel run is slow, fixing parallel-only flakes/races, sharding external resources, or ch

repo: onsi/ginkgo

Popularity

GitHub stars
9.1k
Ranking position
#12304
License
MIT
Updated
10/9/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills