parallelism
ما الذي تفعله
تشرح هذه المهارة كيفية تشغيل اختبارات Ginkgo على عدة عمليات في آن واحد لتوفير الوقت. وهي مناسبة للمطورين الذين تستغرق مجموعات اختباراتهم وقتاً طويلاً.
متى تستخدمها
- ✓عندما تأخذ مجموعة اختبارات Ginkgo وقتاً طويلاً جداً.
- ✓عندما تحتاج إلى أن تستخدم الاختبارات عدة أنوية للمعالج في الوقت نفسه.
- ✓عندما تشارك الاختبارات المنافذ أو المجلدات أو قواعد البيانات وتحتاج إلى إعدادات منفصلة.
رابط المهارة
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/parallelism/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“تستغرق مجموعة اختبارات Go وقتاً طويلاً، هل تستطيع جعلها تعمل بالتوازي باستخدام Ginkgo؟”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تشغّل المهارة نسخاً متعددة من برنامج الاختبار كعمليات منفصلة، ولكل منها نصيبها من الاختبارات، ثم تجمع النتائج في تقرير واحد.
المحتوى التقني (ملف 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 bookdon't race across processes — they each get their ownbook. (Within a process specs still run one at a time.) - The flip side: a
BeforeSuiteruns 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
-rthe 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
--racethat 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
- آخر تحديث
- 9/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
ci
9.1kيساعد وكيلك على إعداد اختبارات Ginkgo في التكامل المستمر، بخيارات موصى بها تكشف علامات التركيز والتعليق المنسية.
debugging-failures
9.1kيساعد وكيلك على معرفة سبب فشل اختبارات Ginkgo، بقراءة سطر النتيجة وسحب الاختبارات الفاشلة ورسائلها بدقة من تقرير JSON.
decorators
9.1kيساعد وكيلك على استخدام مزخرفات اختبارات Ginkgo بشكل صحيح، مثل Serial وOrdered وLabel وFocus والمهلات الزمنية، بشرح وظيفة كل واحدة.
filtering
9.1kيساعد وكيلك على تشغيل جزء فقط من اختبارات Ginkgo، باستخدام التعليق والتخطي والتركيز والتسميات والفلاتر بالترتيب الصحيح.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.