...
1
16
17 package chaosmonkey
18
19 import (
20 "context"
21 "sync/atomic"
22 "testing"
23 )
24
25 func TestDoWithPanic(t *testing.T) {
26 var counter int64
27 cm := New(func(ctx context.Context) {})
28 tests := []Test{
29
30 func(ctx context.Context, sem *Semaphore) {
31 defer atomic.AddInt64(&counter, 1)
32 sem.Ready()
33 },
34
35 func(ctx context.Context, sem *Semaphore) {
36 defer atomic.AddInt64(&counter, 1)
37 sem.Ready()
38 panic("Panic after calling sem.Ready()")
39 },
40
41 func(ctx context.Context, sem *Semaphore) {
42 defer atomic.AddInt64(&counter, 1)
43 panic("Panic before calling sem.Ready()")
44 },
45 }
46 for _, test := range tests {
47 cm.Register(test)
48 }
49 cm.Do(context.Background())
50
51 if int(counter) != len(tests) {
52 t.Errorf("Expected counter to be %v, but it was %v", len(tests), counter)
53 }
54 }
55
View as plain text