Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

test(server): serialize pdf_worker env-mutating tests to fix a flake (#1743)

xerj-orgdcd97380a6d2
diff --git a/engine/crates/xerj-server/tests/pdf_worker.rs b/engine/crates/xerj-server/tests/pdf_worker.rs
index a77974b99..5cd23c3cf 100644
--- a/engine/crates/xerj-server/tests/pdf_worker.rs
+++ b/engine/crates/xerj-server/tests/pdf_worker.rs
@@ -4,6 +4,17 @@ use std::fs;
use std::process::Command;
use std::time::{Duration, Instant};
+// XERJ_PDF_WORKER_BIN is process-global and inherited by the worker child.
+// cargo runs these tests on parallel threads, so one test's set_var/remove_var
+// races another's run_worker spawn (and trips std's set_var concurrency abort).
+// Every test that reads or writes that env var holds this lock for its body.
+// Poison-tolerant: these tests assert and may panic while holding it.
+static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
+
+fn env_guard() -> std::sync::MutexGuard<'static, ()> {
+ ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner())
+}
+
fn write_prose_pdf(path: &std::path::Path) {
let prose = "Quarterly financial results show revenue increased twelve percent while operating margin improved. International customers and subscription renewals drove durable growth across the reporting period.";
let stream = format!("BT /F1 12 Tf 72 720 Td ({prose}) Tj ET");
@@ -77,6 +88,7 @@ fn run_worker(path: &std::path::Path) -> std::process::Output {
#[test]
fn pdf_worker_is_fresh_process_deterministic_and_preserves_page_provenance() {
+ let _env = env_guard();
let temp = tempfile::tempdir().unwrap();
let pdf = temp.path().join("quarterly-report.pdf");
write_prose_pdf(&pdf);
@@ -119,6 +131,7 @@ fn pdf_worker_is_fresh_process_deterministic_and_preserves_page_provenance() {
#[test]
fn corrupt_pdf_failure_is_actionable_and_emits_no_records() {
+ let _env = env_guard();
let temp = tempfile::tempdir().unwrap();
let pdf = temp.path().join("corrupt.pdf");
fs::write(&pdf, b"%PDF-1.4\nnot a PDF").unwrap();
@@ -134,6 +147,7 @@ fn corrupt_pdf_failure_is_actionable_and_emits_no_records() {
#[test]
fn mixed_text_and_empty_pages_disclose_ocr_coverage_without_dropping_good_text() {
+ let _env = env_guard();
let temp = tempfile::tempdir().unwrap();
let pdf = temp.path().join("mixed.pdf");
write_mixed_text_blank_pdf(&pdf);
@@ -157,6 +171,7 @@ fn mixed_text_and_empty_pages_disclose_ocr_coverage_without_dropping_good_text()
#[cfg(unix)]
#[test]
fn parent_drains_overflow_and_timeout_kills_worker_process_group() {
+ let _env = env_guard();
use std::os::unix::fs::PermissionsExt;
let temp = tempfile::tempdir().unwrap();
@@ -221,6 +236,7 @@ fn parent_drains_overflow_and_timeout_kills_worker_process_group() {
#[cfg(unix)]
#[test]
fn pdf_worker_accepts_non_utf8_unix_paths() {
+ let _env = env_guard();
use std::os::unix::ffi::OsStringExt;
let temp = tempfile::tempdir().unwrap();