본문으로 건너뛰기
Skillpedia
테스트9.1k · #12304

parallelism

하는 일

이 스킬은 시간을 줄이기 위해 Ginkgo 테스트를 여러 프로세스에서 동시에 실행하는 방법을 보여 줍니다. 테스트 묶음이 오래 걸리는 개발자를 위한 것입니다.

사용하는 경우

  • ✓Ginkgo 테스트 묶음이 실행하기에 너무 오래 걸릴 때.
  • ✓테스트가 여러 CPU 코어를 동시에 쓰게 하고 싶을 때.
  • ✓병렬 테스트가 포트, 폴더, 데이터베이스를 공유해서 따로 설정이 필요할 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

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.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 Go 테스트 묶음이 너무 오래 걸립니다. Ginkgo로 병렬 실행되게 해 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 테스트 프로그램의 여러 복사본을 각각 별도의 프로세스로 실행하고, 각 프로세스가 테스트의 자기 몫을 맡은 뒤 결과를 하나의 보고서로 합치는 방식을 설명합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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
자주 묻는 질문

병렬 실행이 항상 빠른가요?

보통은 그렇지만, 복사본마다 시작하는 데 시간이 걸리므로 작은 묶음에서는 이득이 상쇄될 수 있습니다.

병렬 실행에 go test를 쓰면 안 되나요?

표준 go test 명령은 별도의 프로세스를 조정할 수 없으므로 ginkgo 명령이 필요합니다.

테스트를 병렬로 실행하면 어떤 위험이 있나요?

포트나 데이터베이스를 공유하는 테스트끼리 충돌할 수 있으므로, 각 프로세스에 별도 설정이 필요합니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
9.1k
순위
#12304
라이선스
MIT
업데이트
2026. 10. 9.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬