Playwright: Isolate Email Tests in Parallel CI
说明与用途
在 CI 并行执行时,使用可抛弃邮箱地址的端到端测试会因共享邮箱状态导致失败。解决方案是为每个测试创建唯一邮箱,验证邮件所有权,测试结束后清理资源,并记录元数据,从而消除竞争并提高 CI 的可靠性。
问题
Email verification tests that pass locally fail in CI when run in parallel due to shared inbox state and race conditions.
结果
Parallel email tests become reliable; flakiness due to shared state is eliminated; CI runs faster and failures are easier to diagnose.
工作流
- 1. Define isolation contract: unique address, record address & correlation, wait for matching message, fresh address on retry, cleanup after evidence.
- 2. Create a Playwright fixture that generates a unique inbox per test using a MailClient.
- 3. In the fixture, construct an owner string from project name, worker index, and test ID.
- 4. Create the inbox via mail.createInbox(owner).
- 5. Provide testMail fixture with address and waitForCode function that polls for the verification email matching the owner.
- 6. Use a finally block to dispose the inbox after test completion, regardless of success.
- 7. Log recipient, subject prefix, and timestamp; redact sensitive data.
- 8. In tests, verify links belong to the current message before clicking.
- 9. In CI, run the debugging checklist: uniqueness, correlation, polling, retry, cleanup, logs.
- 10. Tune polling interval and timeout after confirming isolation.
- 11. Run tests in parallel workers without flakiness.
证据
Email verification tests often pass on a laptop and fail as soon as CI runs four workers.
The fixture also avoids hiding provider errors inside a generic timeout, which is a small but important improvement for QA work.
- 记录日期: 2026-09-21T22:30:21.159Z