A Safer Mailbox Lease for CI Automation
Email tests become unreliable when every pipeline treats the inbox as a permanent shared resource. One job creates an account, another job reads the same messages, and a retry arrives after the test has already finished. The failure looks random, but the underlying problem is ownership. A useful mental model is a mailbox lease. A CI run temporarily owns an isolated disposable address, records why…
CI email tests can become unreliable when multiple jobs share the same inbox. A mailbox lease model provides a solution by temporarily assigning a disposable address to each CI run, recording its lifecycle, and returning it when the run ends. This makes email automation more predictable and easier to reason about. The lease model offers four key pieces of information: ownership (run ID and worker ID), purpose (test suite, branch, or scenario name), validity (expiry time), and outcome (created, used, released, expired).
Implementing a mailbox lease involves creating a storage record with consistent fields, including an explicit state such as leased, consumed, released, or expired. A unique address per parallel worker is recommended, and events like verification requests should be tracked separately. A run manifest containing the run ID, suite name, address reference, lease state, timestamps, and events should be created and shared with CI jobs.
When a test fails, a compact bundle should be saved containing the run manifest, expected event type, timestamps, selected message ID, poll count, and failure category. To avoid privacy concerns, the address reference should not be exposed in logs, and raw message bodies should not be uploaded by default. Cleanup should be handled by a cleanup path, either releasing or expiring the lease, and any cleanup failures should be reported separately to maintain clear error handling.
Sharing a lease within a scenario is appropriate when the test flow intentionally includes multiple steps, while unrelated tests and parallel workers should use separate leases. A lease is more than just a timeout, as it includes ownership, state transitions, event IDs, and cleanup.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.