(mess) Stuffing commit.
This commit is contained in:
+14
-14
@@ -10,11 +10,10 @@ Chaos testing applies the invariant-driven verification approach from [Invariant
|
||||
const result = await fastify.apophis.contract({
|
||||
runs: 50,
|
||||
chaos: {
|
||||
probability: 0.1, // 10% of requests get chaos
|
||||
delay: { probability: 1, minMs: 100, maxMs: 500 },
|
||||
error: { probability: 1, statusCode: 503 },
|
||||
dropout: { probability: 1 },
|
||||
corruption: { probability: 1 },
|
||||
delay: { probability: 0.1, minMs: 100, maxMs: 500 },
|
||||
error: { probability: 0.1, statusCode: 503 },
|
||||
dropout: { probability: 0.05 },
|
||||
corruption: { probability: 0.1 },
|
||||
},
|
||||
});
|
||||
```
|
||||
@@ -26,7 +25,6 @@ const result = await fastify.apophis.contract({
|
||||
Adds artificial latency. Tests timeout contracts:
|
||||
|
||||
```apostl
|
||||
timeout_occurred(this) == false
|
||||
response_time(this) < 1000
|
||||
```
|
||||
|
||||
@@ -37,7 +35,8 @@ response_time(this) < 1000
|
||||
Forces HTTP status codes. Tests error-handling contracts:
|
||||
|
||||
```apostl
|
||||
if status:503 then response_body(this).retry_after != null
|
||||
// Behavioral: when the service is unavailable, the client receives a valid retry signal
|
||||
if status:503 then response_headers(this).retry-after > 0
|
||||
```
|
||||
|
||||
### Dropout
|
||||
@@ -45,7 +44,8 @@ if status:503 then response_body(this).retry_after != null
|
||||
Simulates network failure (status 0). Tests fallback contracts:
|
||||
|
||||
```apostl
|
||||
status:200 || status:0
|
||||
// Behavioral: partial failure must still return previously cached data
|
||||
if status:0 then response_body(this).cached_data == previous(response_body(GET /cache/{request_params(this).key}))
|
||||
```
|
||||
|
||||
### Corruption
|
||||
@@ -53,7 +53,8 @@ status:200 || status:0
|
||||
Mutates response bodies. Tests parsing robustness:
|
||||
|
||||
```apostl
|
||||
response_body(this).id != null
|
||||
// Behavioral: corrupted requests maintain traceability for debugging
|
||||
if status:400 then response_body(this).request_id == request_headers(this).x-request-id
|
||||
```
|
||||
|
||||
## Corruption Strategies
|
||||
@@ -104,7 +105,7 @@ Failed tests include chaos events in diagnostics:
|
||||
```json
|
||||
{
|
||||
"statusCode": 503,
|
||||
"error": "Contract violation: status:200",
|
||||
"error": "Contract violation: if status:503 then response_headers(this).retry-after > 0",
|
||||
"chaosEvents": [
|
||||
{
|
||||
"type": "error",
|
||||
@@ -122,7 +123,7 @@ Failed tests include chaos events in diagnostics:
|
||||
|
||||
1. **Start small**: `probability: 0.05` (5% of requests)
|
||||
2. **Test one failure mode at a time**: Comment out other chaos types
|
||||
3. **Verify contracts handle chaos**: `if status:503 then response_body(this).error != null`
|
||||
3. **Verify contracts handle chaos**: `if status:503 then response_code(GET /health) == 200`
|
||||
4. **Use seeds for reproducibility**: `seed: 42` makes chaos deterministic
|
||||
|
||||
## Example: Testing Retry Logic
|
||||
@@ -131,7 +132,7 @@ Failed tests include chaos events in diagnostics:
|
||||
fastify.get('/data', {
|
||||
schema: {
|
||||
'x-ensures': [
|
||||
'if status:503 then response_headers(this).retry-after != null',
|
||||
'if status:503 then response_headers(this).retry-after > 0',
|
||||
'redirect_count(this) <= 3',
|
||||
],
|
||||
},
|
||||
@@ -140,8 +141,7 @@ fastify.get('/data', {
|
||||
// Test
|
||||
const result = await fastify.apophis.contract({
|
||||
chaos: {
|
||||
probability: 0.2,
|
||||
error: { probability: 1, statusCode: 503 },
|
||||
error: { probability: 0.2, statusCode: 503 },
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user