惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
罗磊的独立博客
Last Week in AI
Last Week in AI
B
Blog
IT之家
IT之家
S
SegmentFault 最新的问题
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - 聂微东
U
Unit 42
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
MyScale Blog
MyScale Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Testing Webhooks: The Pattern I Keep Reaching For
Rishi Gaurav · 2026-06-26 · via DEV Community

Three years ago, my webhook tests involved ngrok, a sleep(5) call, and crossed fingers. The current pattern uses none of those.

If you've ever tested webhook integrations, this probably sounds familiar.

Start your local application.

Launch ngrok.

Copy the temporary URL into the third-party application.

Trigger an event.

Wait a few seconds.

Hope the webhook arrives.

Add another sleep(5) because it didn't.

Run the test again.

Eventually, it works.

Until the URL changes.

Or the network hiccups.

Or your CI pipeline doesn't have access to ngrok.

Webhook testing has always been slightly awkward because you're validating an asynchronous conversation between two independent systems. Unlike a traditional API request where the client controls both the request and the response, webhooks require your application to become the server.

After building and testing webhook integrations for payment gateways, CRMs, messaging platforms, and SaaS applications, I've settled on a pattern that is simple, deterministic, and works just as well in CI as it does on a developer laptop.

It revolves around one idea:

Never test webhooks directly. Test your webhook receiver.

Here's the pattern I keep coming back to.


The "Inbox" Pattern — A Tiny HTTP Receiver with a Queue

Most webhook tests try to verify everything at once.

A webhook is sent.

Your application receives it.

Business logic runs.

The database updates.

Notifications are triggered.

Logs are written.

When something fails, it's difficult to know where the problem actually occurred.

Instead, separate reception from processing.

Imagine your webhook receiver doing only three things:

  1. Accept the HTTP request.
  2. Validate it.
  3. Place it into an inbox queue.

That's it.

Processing happens later.

Your receiver becomes extremely small.

Webhook Sender
        │
        ▼
HTTP Receiver
        │
        ▼
Inbox Queue
        │
        ▼
Business Processing

Now every stage can be tested independently.


Why This Pattern Works

The inbox acts as a temporary mailbox.

Your webhook endpoint only answers one question:

"Did we receive a valid webhook?"

Everything after that belongs to a different set of tests.

Benefits include:

  • Faster execution
  • Easier debugging
  • Better retry handling
  • Clearer separation of concerns

Instead of waiting for an entire workflow to complete, your test simply verifies:

  • HTTP 200 returned
  • Payload stored
  • Metadata captured
  • Queue entry created

The business logic can be validated separately.


A Better Mental Model

Think of your webhook endpoint like an email inbox.

Receiving the email isn't the same as processing it.

If the inbox works reliably, downstream processing becomes much easier to reason about.


Signature Verification: The Test That Catches 80% of Integration Bugs

Most webhook providers sign every request.

Examples include:

  • Stripe
  • GitHub
  • Shopify
  • Slack
  • Twilio

The sender computes a cryptographic signature.

Your receiver verifies it before trusting the payload.

Yet this is one of the most frequently skipped tests.


Why Signature Validation Matters

Imagine this request:

POST /webhook

Headers:

X-Signature:
a9f72d...

Payload:

{
  "event": "payment.completed"
}

If your signature verification is wrong, one of two things happens:

  1. Legitimate webhooks are rejected.
  2. Fake webhooks are accepted.

Neither outcome is desirable.


The Three Signature Tests Every Suite Needs

Instead of testing only the happy path, include:

Valid Signature

Expected:

200 OK

Webhook accepted.


Modified Payload

Change one character after computing the signature.

Expected:

401 Unauthorized

The payload should fail verification.


Wrong Secret

Generate the signature using an incorrect secret.

Expected:

401 Unauthorized

This single test catches an enormous number of configuration mistakes before production.

In my experience, signature verification accounts for the majority of webhook integration issues discovered during implementation.


Retry Behavior: How to Test It Without Waiting 30 Minutes

Many webhook providers retry failed deliveries.

Sometimes immediately.

Sometimes after several minutes.

Sometimes using exponential backoff.

Waiting for real retry intervals makes automated testing painfully slow.

Fortunately, you don't need to.


Fake the Clock

Instead of relying on time itself, make retry scheduling injectable.

For example:

Retry Policy

Attempt 1

Attempt 2

Attempt 3

During production:

5 min
15 min
30 min

During testing:

10 ms
20 ms
40 ms

Exactly the same logic.

Different timing.


What Should Be Tested?

A good retry suite verifies:

  • Failed delivery schedules another attempt.
  • Successful delivery stops future retries.
  • Maximum retry count is respected.
  • Duplicate retries don't create duplicate business events.

Every one of these can execute in a few hundred milliseconds.

No waiting required.


Simulate Temporary Failures

Instead of breaking the network, simply return:

HTTP 500

twice.

Then:

HTTP 200

on the third request.

Verify:

  • Three attempts occurred.
  • Final processing happened once.
  • Queue contains one completed event.

Deterministic.

Fast.

Reliable.


Out-of-Order Delivery — The Test Most Suites Skip

Here's something many engineers don't discover until production:

Webhook delivery order is not guaranteed.

Imagine two events.

Order Updated

arrives before:

Order Created

Perfectly legal.

Many providers explicitly document that ordering should not be assumed.

Yet countless applications accidentally depend on chronological delivery.


A Simple Example

Expected order:

Create Customer
↓

Activate Subscription

Actual delivery:

Activate Subscription
↓

Create Customer

If your system assumes ordering, the second event fails.

Production becomes inconsistent.


How to Test It

Instead of replaying events chronologically:

Send:

Event 2

before:

Event 1

Observe:

  • Does processing retry?
  • Is the event delayed?
  • Does the application recover automatically?

If not, you've discovered an important resilience gap.


Idempotency Matters Too

Out-of-order delivery often appears alongside duplicate delivery.

Your suite should verify:

Event A
↓

Event A
↓

Event B

creates exactly one business outcome.

The webhook may arrive twice.

The invoice should not.


The Webhook Test Template, in 40 Lines

The final pattern isn't tied to any programming language.

Almost every webhook test follows the same structure.

Arrange

Create:

  • Test payload
  • Signature
  • Receiver
  • Inbox

Act

Send:

POST /webhook


Assert Reception

Verify:

  • Status code
  • Signature validation
  • Queue entry
  • Metadata

Assert Processing

Process the inbox.

Verify:

  • Business action
  • Database changes
  • Event completion

Assert Idempotency

Replay exactly the same webhook.

Verify:

  • No duplicate records
  • No duplicate emails
  • No duplicate invoices

That's essentially the entire template.

Most webhook integrations differ only in payload shape and signature algorithm.

The testing pattern remains almost identical.


Putting It All Together

A mature webhook testing strategy usually covers five layers:

Layer What It Verifies
Receiver HTTP endpoint accepts requests
Signature Request authenticity
Inbox Reliable persistence
Processor Business logic
Idempotency Safe duplicate handling

Notice what's missing.

There are:

  • No arbitrary sleep calls.
  • No waiting for asynchronous timing.
  • No dependence on external tunnels.
  • No manual inspection.

Every component becomes deterministic.

Every failure becomes easier to diagnose.

Every test becomes suitable for local execution and continuous integration.


Final Thoughts

Webhook integrations are naturally asynchronous, but that doesn't mean your tests have to be unpredictable.

By separating webhook reception from business processing, validating signatures independently, simulating retries instead of waiting for them, and deliberately testing out-of-order delivery, you can build a test suite that's both fast and resilient.

The biggest improvement I made wasn't switching frameworks or buying another testing tool.

It was changing the architecture of the tests themselves.

Today, the same webhook tests run locally, in pull requests, and in production validation pipelines without relying on temporary tunnels, artificial delays, or manual verification.

That's exactly the kind of reliability automated testing should provide.

If you're looking for the CI integrations we ship for receiving these webhooks, explore:

https://totalshiftleft.ai/integrations

The fewer moving parts your webhook tests depend on, the more confidence you'll have when the real events start arriving in production.