about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-08 14:15:13 +0000
committerPjotr <wrk@bosa.lan>2026-11-08 14:15:24 +0000
commit51739ea82f3543ac6e28c8392d6d62957c021b3a (patch)
tree7663b917022f709b343933ca036e6f420a3a460a /tests
parent1f76ef2ef19ae36882236be7c016f0ab98d31f11 (diff)
downloadgenenetwork4-51739ea82f3543ac6e28c8392d6d62957c021b3a.tar.gz
compute: gate R/qtl at eight concurrent scans, one per caller
`POST /compute/rqtl` now takes up to `RQTL_MAX_CONCURRENT` slots (default
8, read when the gate is built) with the same one-job-per-caller rule as
GEMMA: a second submission from the same token while its scan is running
or queued is refused `409 compute_busy`; a submission that finds every
slot taken waits for one to come free. Eight because an R/qtl scan is a
single-threaded Rscript on a 96-core box; not more, because a scan on a
3 000-individual cross is minutes of CPU and the same machine serves the
database. Unlike GEMMA's single slot, concurrent scans share no cache
(R/qtl results are uncached), so the only cost is the CPU they take.

Two flaws only appeared once there was more than one slot:

- the "what is running" record was a single `Option<Active>`, so a
  refusal quoted whichever job had most recently taken a slot -- robw's
  409 named JoM's run id. It is now a map keyed by subject, and
  `a_refusal_quotes_the_callers_own_run_id` pins it;
- `Busy::describe` took the endpoint identifier, so the message read
  "your rqtl job"; the decorator takes a separate `label` ("R/qtl") from
  the status path.

The test suite hit the rule itself: six compute tests in tests/rqtl.rs
share one token, and cargo runs them on several threads, so three were
refused instead of run. They now serialise on a module mutex, with a
comment saying why -- the same lesson clients need, that parallelism
means more tokens, not more requests from one.

* src/compute_gate.rs (rqtl()): eight slots from `RQTL_MAX_CONCURRENT`;
`Gate::new(permits)` was already parameterised. `running` becomes a map
keyed by subject, since one record cannot name N jobs. Module doc talks
about slots rather than a single slot. Tests: eight subjects run and the
ninth waits, a caller still may not take two even with slots free, and a
refusal quotes the caller's own run id.
* src/config.rs: RQTL_MAX_CONCURRENT, default 8, fixed at first use.
* gnauth-macros/src/lib.rs: `label = "…"`, so prose and status path are
independent.
* src/routes/rqtl.rs: the decorator, and `_token` becomes `token`, which
it needs.
* tests/rqtl.rs: compute tests serialised.
* README.md (/compute/rqtl), docs/www/ai-instruction.md (4a),
docs/www/operator-checklist.md: the numbers per endpoint, and that more
parallelism means more tokens.
Diffstat (limited to 'tests')
-rw-r--r--tests/rqtl.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/rqtl.rs b/tests/rqtl.rs
index 6674193..20164e5 100644
--- a/tests/rqtl.rs
+++ b/tests/rqtl.rs
@@ -14,6 +14,20 @@ use serde_json::Value;
 
 mod common;
 
+/// `/compute/rqtl` allows one job per caller, and every test in this file
+/// uses the same token, so two compute tests running at once would have one
+/// of them refused with `409 compute_busy`. Cargo runs a file's tests on
+/// several threads, so they take this lock first.
+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 rscript_available() -> bool {
     std::process::Command::new("Rscript")
         .arg("--version")
@@ -38,6 +52,7 @@ fn bxd_samples() -> Value {
 
 #[tokio::test]
 async fn compute_rqtl_maps_a_qtl_from_the_bxd_riset_fixture() {
+    let _serial = serialised();
     if !rscript_available() {
         eprintln!(
             "skipping compute_rqtl_maps_a_qtl_from_the_bxd_riset_fixture: Rscript not on PATH"
@@ -116,6 +131,7 @@ async fn compute_rqtl_maps_a_qtl_from_the_bxd_riset_fixture() {
 
 #[tokio::test]
 async fn compute_rqtl_with_permutations_returns_thresholds() {
+    let _serial = serialised();
     if !rscript_available() {
         eprintln!(
             "skipping compute_rqtl_with_permutations_returns_thresholds: Rscript not on PATH"
@@ -185,6 +201,7 @@ async fn compute_rqtl_requires_a_token() {
 
 #[tokio::test]
 async fn compute_rqtl_rejects_an_invalid_run_id() {
+    let _serial = serialised();
     let Some(token) = common::auth_token().await else {
         eprintln!(
             "skipping compute_rqtl_rejects_an_invalid_run_id: no token (see docs/gn-auth.md)"
@@ -243,6 +260,7 @@ async fn rqtl_status_requires_a_token() {
 
 #[tokio::test]
 async fn compute_rqtl_rejects_a_run_id_already_in_use() {
+    let _serial = serialised();
     let Some(token) = common::auth_token().await else {
         eprintln!(
             "skipping compute_rqtl_rejects_a_run_id_already_in_use: no token (see docs/gn-auth.md)"
@@ -286,6 +304,7 @@ async fn compute_rqtl_rejects_a_run_id_already_in_use() {
 
 #[tokio::test]
 async fn compute_rqtl_streams_progress_while_running() {
+    let _serial = serialised();
     if !rscript_available() {
         eprintln!("skipping compute_rqtl_streams_progress_while_running: Rscript not on PATH");
         return;
@@ -355,6 +374,7 @@ async fn compute_rqtl_streams_progress_while_running() {
 /// a 21k-marker scan would make this a mapping rather than a test.
 #[tokio::test]
 async fn compute_rqtl_fits_a_case_attribute_as_a_covariate() {
+    let _serial = serialised();
     if !rscript_available() {
         eprintln!("skipping compute_rqtl_fits_a_case_attribute_as_a_covariate: Rscript not on PATH");
         return;