fix(tests): remove SMTP-env race behind the email-notification flake (LC-363) #374

Merged
longjacksonle merged 1 commit from fix/lc-363-email-notification-flake into main 2026-06-19 14:34:58 +02:00

Fixes LC-363.

Root cause

Both email_notification_post_path and email_notification_dispatch built their test mailer by setting the four process-global LETS_CHAT_SMTP_* env vars, calling Mailer::from_env(), then removing them - inside setup(), which runs per test on parallel threads. Under full-suite concurrency the windows overlapped: a concurrent remove_var landed between another test's set_var and from_env(), so that test got mailer: None, the dispatcher returned SkippedNoMailer, no reply-token was minted, and the count == 1 assert failed. Load-sensitive, always green on isolated re-run - the exact LC-363 symptom.

Fix

Add a #[doc(hidden)] test-only Mailer::unreachable_for_tests() that builds the same unreachable-host mailer (127.0.0.1:1, TLS none) directly, with no environment access, and use it in both test files. No process-global mutation, so the tests can no longer race. (Production still goes through from_env exclusively.)

Validation

  • Ran the two binaries together 5x: zero failures.
  • just test and just test-saas both green on the first run (the saas suite had been flaking ~1-in-3 on these binaries before).

3 files: server/src/mail.rs, server/tests/email_notification_post_path.rs, server/tests/email_notification_dispatch.rs.

Fixes LC-363. ## Root cause Both `email_notification_post_path` and `email_notification_dispatch` built their test mailer by setting the four process-global `LETS_CHAT_SMTP_*` env vars, calling `Mailer::from_env()`, then removing them - inside `setup()`, which runs per test on parallel threads. Under full-suite concurrency the windows overlapped: a concurrent `remove_var` landed between another test's `set_var` and `from_env()`, so that test got `mailer: None`, the dispatcher returned `SkippedNoMailer`, no reply-token was minted, and the `count == 1` assert failed. Load-sensitive, always green on isolated re-run - the exact LC-363 symptom. ## Fix Add a `#[doc(hidden)]` test-only `Mailer::unreachable_for_tests()` that builds the same unreachable-host mailer (127.0.0.1:1, TLS none) directly, with no environment access, and use it in both test files. No process-global mutation, so the tests can no longer race. (Production still goes through `from_env` exclusively.) ## Validation - Ran the two binaries together 5x: zero failures. - `just test` and `just test-saas` both green on the first run (the saas suite had been flaking ~1-in-3 on these binaries before). 3 files: `server/src/mail.rs`, `server/tests/email_notification_post_path.rs`, `server/tests/email_notification_dispatch.rs`.
fix(tests): stop the email-notification flake from racing on SMTP env vars (LC-363)
All checks were successful
check-secrets / Nosey parker (pull_request) Successful in 3s
check-secrets / Nosey parker (push) Successful in 3s
check-secrets / TruffleHog (push) Successful in 5s
check-secrets / Kingfisher (push) Successful in 6s
check-secrets / TruffleHog (pull_request) Successful in 6s
Create release / Create release from merged PR (pull_request) Has been skipped
check-secrets / Kingfisher (pull_request) Successful in 5s
Check / clippy + fmt + tests (pull_request) Successful in 3m0s
9e34c9778f
Both email_notification_* test binaries built their test mailer by setting the four process-global LETS_CHAT_SMTP_* env vars, calling Mailer::from_env(), then removing them again - inside setup(), which runs per test on parallel threads. Under full-suite load the windows overlapped: a concurrent remove_var landed between another test's set_var and from_env(), so that test got mailer = None, the dispatcher returned SkippedNoMailer, no reply-token was minted, and the count-1 assert failed. The failure was load-sensitive (only under full-suite concurrency) and always passed on an isolated re-run, which is exactly the LC-363 symptom.

Add a `#[doc(hidden)]` test-only `Mailer::unreachable_for_tests()` that builds the same unreachable-host mailer directly (no env), and use it in both files. No process-global env mutation, so the tests can no longer race. Ran the two binaries together 5x with zero failures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
longjacksonle deleted branch fix/lc-363-email-notification-flake 2026-06-19 14:34:58 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/lets-chat!374
No description provided.