-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (41 loc) · 1.1 KB
/
Copy pathmain.go
File metadata and controls
51 lines (41 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2026 Onur Cinar.
// The source code is provided under MIT License.
// https://github.com/cinar/resile
package main
import (
"context"
"errors"
"fmt"
"time"
"github.com/cinar/resile"
"github.com/cinar/resile/chaos"
)
func main() {
ctx := context.Background()
// Configure chaos injection.
// In production, you might want to load this from environment variables.
cfg := chaos.Config{
ErrorProbability: 0.5,
InjectedError: errors.New("synthetic failure"),
LatencyProbability: 0.2,
LatencyDuration: 100 * time.Millisecond,
}
fmt.Println("Running with chaos injection (50% error, 20% latency)...")
for i := 1; i <= 5; i++ {
fmt.Printf("\n--- Request %d ---\n", i)
start := time.Now()
err := resile.DoErr(ctx, func(ctx context.Context) error {
fmt.Println("Executing business logic...")
return nil
},
resile.WithRetry(3),
resile.WithChaos(cfg),
)
duration := time.Since(start)
if err != nil {
fmt.Printf("Request failed after retries: %v (took %v)\n", err, duration)
} else {
fmt.Printf("Request succeeded (took %v)\n", duration)
}
}
}