forked from octolab/breaker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiplexer_test.go
60 lines (45 loc) · 1.11 KB
/
multiplexer_test.go
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
52
53
54
55
56
57
58
59
60
package breaker_test
import (
"context"
"os"
"testing"
"time"
. "github.com/kamilsk/breaker"
)
func TestMultiplex(t *testing.T) {
t.Parallel()
t.Run("with breakers", func(t *testing.T) {
t.Parallel()
timeout := 5 * delta
br := Multiplex(
BreakByChannel(context.TODO().Done()),
BreakByContext(context.WithCancel(context.TODO())),
BreakByDeadline(time.Now().Add(time.Hour)),
BreakBySignal(os.Interrupt),
BreakByTimeout(timeout),
)
start := time.Now()
<-br.Done()
checkDuration(t, start.Add(timeout), time.Now())
checkBreakerIsReleased(t, br)
})
t.Run("without breakers", func(t *testing.T) {
t.Parallel()
br := Multiplex()
checkBreakerIsReleasedFast(t, br)
})
t.Run("close breaker", func(t *testing.T) {
t.Parallel()
br := Multiplex(BreakByTimeout(time.Hour))
checkBreakerIsNotReleased(t, br)
br.Close()
checkBreakerIsReleased(t, br)
})
t.Run("close breaker multiple times", func(t *testing.T) {
t.Parallel()
br := Multiplex(BreakByTimeout(time.Hour))
checkBreakerIsNotReleased(t, br)
closeBreakerConcurrently(br, times)
checkBreakerIsReleased(t, br)
})
}