about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-08 16:32:59 +0000
committerPjotr <wrk@bosa.lan>2026-11-08 16:32:59 +0000
commitab5fef05237309667dd2ca7f835a5fbf9c71a12a (patch)
tree94267f7fa6c5f27fe6d5093d1280c48170ffe164 /tests
parente934e755f14648fff6ebac07e9cf9e5b37cb3fe4 (diff)
downloadgenenetwork4-ab5fef05237309667dd2ca7f835a5fbf9c71a12a.tar.gz
compute: gate GEMMA from 50 individuals, R/qtl from 1 000
One threshold for both engines was the wrong shape. For R/qtl the
interesting line is where a `scanone` stops being seconds (a few hundred
individuals is seconds of one core), so 1 000 stays. For GEMMA it is much
earlier, and not because of the runtime:

- every GEMMA run goes through **one shared cache directory**
  (`GEMMA_CACHE_DIR`), where `gemma-wrapper` extracts per-chromosome
  kinship archives of hundreds of megabytes by content hash. Two runs at
  once are two writers over the same archives, and a half-extracted kinship
  another run reads surfaces as a GEMMA failure;
- a real BXD WGS run is ~19 s of every core it can get; UM-HET3's 6 382
  individuals write 207 MB of kinship per chromosome.

So `GEMMA_LARGE_PANEL` is 50 -- the smallest real panel, which means every
mapping request is gated in practice, and only a handful of individuals (a
four-way cross's parents, a probe of the pipeline) runs free. `ravanan`
uses the same number, since it writes into the same cache. The threshold
moved onto the `Gate` (`large_panel()`, `is_large()`), so each endpoint
carries its own; the policy, the slots and the 409 are unchanged.

Tests, asked and answered: at 50 the three gemma tests that do real work
(fixtures 198 individuals, BXD.4 with `Status` 93, ravanan 198) are gated
and share one token, so on a cold cache two of them at once would collide
into `409 compute_busy` -- a gate doing its job, failing a test that only
wanted to map something. They now take a lock, and only they do; the
validation tests stay parallel, and the rqtl suite is untouched (its gate
still starts at 1 000). Verified: with `GEMMA_CACHE_DIR` pointed at an
empty directory, `cargo test --test gemma` is green twice in a row, 18 s
per run, i.e. really recomputing.

* src/compute_gate.rs: `RQTL_LARGE_PANEL` (1 000), `GEMMA_LARGE_PANEL`
  (50), `Gate::large_panel`/`is_large`, `Gate::new(permits, large_panel)`;
  the test that pinned one number now pins both and that each endpoint is
  wired to its own.
* tests/gemma.rs: the three real-job tests take the lock, and say why.
* README.md, docs/www/ai-instruction.md, docs/www/operator-checklist.md:
  the two thresholds and the cache-directory reason for the lower one.

277 tests pass; the same four as before do not.
Diffstat (limited to 'tests')
-rw-r--r--tests/gemma.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/gemma.rs b/tests/gemma.rs
index ac01492..22531f9 100644
--- a/tests/gemma.rs
+++ b/tests/gemma.rs
@@ -12,6 +12,21 @@ mod common;
 
 /// True only when gemma-wrapper is actually runnable. `-v` is cheap and
 /// does not touch the cache dir or invoke the real GEMMA binary.
+/// The three tests that run a real GEMMA job take this lock: they share
+/// one cache directory *and* one token, so on a cold cache two of them at
+/// once would both be gated (GEMMA's threshold is 50 individuals) and the
+/// second would be refused with `409 compute_busy` -- a gate doing its job,
+/// which would fail the test that was only trying to map something.
+static COMPUTE_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
+
+/// Take [`COMPUTE_LOCK`], ignoring poisoning (one failing test must not
+/// fail the rest).
+fn serialised() -> std::sync::MutexGuard<'static, ()> {
+    COMPUTE_LOCK
+        .lock()
+        .unwrap_or_else(|poisoned| poisoned.into_inner())
+}
+
 fn gemma_wrapper_available() -> bool {
     std::process::Command::new("gemma-wrapper")
         .arg("-v")
@@ -52,6 +67,7 @@ fn bxd_trait_values() -> Vec<Option<f64>> {
 
 #[tokio::test]
 async fn compute_gemma_maps_a_qtl_from_the_bxd_fixtures() {
+    let _serial = serialised();
     if !gemma_wrapper_available() {
         eprintln!(
             "skipping compute_gemma_maps_a_qtl_from_the_bxd_fixtures: gemma-wrapper not on PATH"
@@ -218,6 +234,7 @@ async fn compute_gemma_maps_a_qtl_from_the_bxd_fixtures() {
 
 #[tokio::test]
 async fn compute_gemma_ravanan_maps_a_qtl_from_the_bxd_fixtures() {
+    let _serial = serialised();
     if !ravanan_available() || !gemma_wrapper_available() || !ccwl_available() {
         eprintln!(
             "skipping compute_gemma_ravanan_maps_a_qtl_from_the_bxd_fixtures: ravanan, gemma-wrapper or ccwl not on PATH"
@@ -463,6 +480,7 @@ async fn compute_gemma_rejects_a_run_id_already_in_use() {
 /// fitted as one ordinal number.
 #[tokio::test]
 async fn compute_gemma_fits_a_case_attribute_as_a_covariate() {
+    let _serial = serialised();
     if !gemma_wrapper_available() {
         eprintln!(
             "skipping compute_gemma_fits_a_case_attribute_as_a_covariate: gemma-wrapper not on PATH"