Dishant Singh

Apr 27, 2026 • 2 min read

Why Your OTP & Email Tests Fail in CI (And How I Finally Fixed It)

Why Your OTP & Email Tests Fail in CI (And How I Finally Fixed It)

🧠 The Problem No One Talks About

If you’ve ever tested a signup flow with email verification or OTP… you’ve probably seen this:

  • Tests pass locally ✅

  • CI randomly fails ❌

  • Retries create weird edge cases 🤯

And the worst part?

👉 You don’t know why it failed.

Was it:

  • Email delay?

  • Wrong OTP picked?

  • Parsing issue?

  • Multiple emails sent?

Most tools don’t tell you. They just give you:

“Timeout exceeded”


⚠️ The Real Issue: Email Is an Async System

Most developers treat email in tests like a simple API response.

But it’s not.

It’s a distributed, asynchronous system:

  • Email provider latency varies (1–5s+)

  • Retries can generate multiple emails

  • OTP parsing can fail silently

  • CI environments behave differently than local

This is why:

👉 Mocking works… until it doesn’t
👉 Real email testing works… but becomes flaky


🧪 What I Tried (And Why It Didn’t Work)

1. Mocking Email

  • Fast ✅

  • Deterministic ✅

  • Completely unrealistic ❌

👉 Doesn’t catch real delivery issues


2. Using Temp Mail Tools

  • Easy to use ✅

  • Works for basic flows ✅

But tools like typical temp mail platforms are built for:

  • privacy

  • spam avoidance

not for:

👉 testing auth systems


3. Polling APIs (Mailosaur, etc.)

  • Better than scraping ✅

  • Still limited ❌

Problem:

👉 You still don’t know what happened inside the flow


💡 The Breakthrough: Track the Full Flow

Instead of just waiting for OTP…

I started tracking:

  • when the email was triggered

  • when it actually arrived

  • when OTP was extracted

  • how long each step took


Example:

Signup triggered → 0ms 
Email received → 3.8s 
OTP extracted → 4.1s 

Suddenly:

👉 failures weren’t random anymore
👉 they were explainable


🔥 This Changed Everything

Now instead of:

❌ “Test failed”

I get:

Email delayed by 4.2s → exceeded timeout

And that’s a completely different experience.


🧰 What I Built Around This

I ended up building a small system around this idea:

  • programmatic inbox creation

  • real-time email detection

  • OTP extraction

  • timeline debugging

  • CI-friendly APIs + SDKs

So instead of just:

await waitForOtp()

You actually understand:

👉 what happened behind the scenes


If you’re curious, this is what I’ve been working on:
https://www.freecustom.email/api


🤔 Question for You

How are you currently testing email/OTP flows?

  • Fully mocked?

  • Using temp mail tools?

  • Real provider testing in CI?

And more importantly:

👉 how do you debug failures when they happen?


💬 Final Thought

Most developers don’t struggle with writing tests.

They struggle with:

👉 understanding why tests fail


And email-based auth flows are one of the biggest hidden sources of that pain.

Join Dishant on Peerlist!

Join amazing folks like Dishant and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

3

0