Skip to main content
REST API

Circuit Breaker

RetryErrorValidateExpert

What you will learn

  • Verify the open โ†’ half-open โ†’ closed transitions and their threshold triggers
  • Assert fast-fail when circuit is open โ€” slow fallbacks cascade under load
  • Test that a single successful probe doesn't prematurely close a still-broken circuit

Description

Test circuit breaker states: closed, open, half-open.

Test Scenario

// Trip the breaker: POST action 'failure' until the threshold (5) is reached
for (let i = 0; i < 5; i++) {
  await request.post('/api/v1/circuit-breaker', { data: { action: 'failure' } });
}

// Read status โ€” state lives under .stats and is upper-case
const response = await request.get('/api/v1/circuit-breaker');
const body = await response.json();
expect(body.stats.state).toBe('OPEN');
Endpoint/api/v1/circuit-breaker

Testing Tips

  • โ€ขMultiple failures open the circuit
  • โ€ขOpen circuit returns fast failure
  • โ€ขHalf-open allows test requests
// Playwright API Testing - REST
import { test, expect } from '@playwright/test';
test('REST API request', async ({ request }) => {
const response = await request.get('/api/v1/resource');
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const data = await response.json();
expect(data).toBeDefined();
});

Challenge ID: rest-circuit-breaker

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/circuit-breaker

Press Enter to send