build: run rust-module test forks in parallel
- Commit
5d654dd621e3de9a74ca53ad62adce4cd2e6eba9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-20 20:05 UTC (15 days ago)
- Parents
18b016f
:appstore:testDevUnitTest has timed out in CI three runs running. Root cause: modules with a Rust host library get forkEvery = 1 on every Test task (a JNI library binds to one classloader per JVM, conflicting with Robolectric's sandbox loader), and maxParallelForks was never set - so appstore's 152 classes ran as 152 sequential JVM forks, each paying JVM + Robolectric sandbox + resource + JaCoCo startup. Local estimate 13-16 min on 192 cores; on CI's 6 vCPU that is 35-60 min. forkEvery stays (the JNI constraint is real); forks now run in parallel: maxParallelForks = availableProcessors/2 clamped to 1..6 - memory-bounded (1-2 GB per Robolectric fork): 3 forks in CI, 6 on the dev box. Applies to all 41 unit-test tasks of Rust-host modules, direct and transitive. Configuration-cache safe (plain Int from availableProcessors at configuration time). Verified: effective values inspected (appstore forkEvery=1, maxParallelForks=6), appstore RouteSerializerTest passes.
Diff
build-logic/src/main/kotlin/RustNative.kt
diff --git a/build-logic/src/main/kotlin/RustNative.kt b/build-logic/src/main/kotlin/RustNative.ktindex 43927dc73c..3d2d18c8c0 100644--- a/build-logic/src/main/kotlin/RustNative.kt+++ b/build-logic/src/main/kotlin/RustNative.kt@@ -935,6 +935,20 @@ fun Project.wireRustHostLibsForUnitTests() { // so mixing both in one JVM fails with "already loaded in another classloader". // One JVM per test class keeps each loader's System.loadLibrary isolated. forkEvery = 1+ // forkEvery = 1 alone would run those per-class JVMs one at a time+ // (Gradle's default maxParallelForks = 1): e.g. appstore's 152 test+ // classes become 152 sequential JVM + Robolectric sandbox startups.+ // Run several class-forks concurrently instead. Each Robolectric+ // fork costs roughly 1-2 GB (JVM + sandbox + resources + JaCoCo),+ // so the cap is memory-bounded, not core-proportional: half the+ // processors, clamped to 1..6. On 6-vCPU / 14 GB CI that is 3+ // forks (~3-6 GB of test JVMs beside the Gradle daemon); on a+ // many-core dev box it still stops at 6. Computed from a plain+ // Int at configuration time, so the configuration cache is+ // unaffected. Applies per Test task: smaller rustNativeLib+ // modules get the same parallelism headroom but only ever fork+ // as many JVMs as they have test classes queued.+ maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceIn(1, 6) } } }