-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
81 lines (69 loc) · 1.84 KB
/
Copy pathmain_test.go
File metadata and controls
81 lines (69 loc) · 1.84 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"context"
"testing"
"time"
registry "github.com/Ishan27g/registry/golang/registry/package"
)
var singleRoundNumMessages = 16
var zone1 = envFile + "1.leader.env"
var zone2 = envFile + "2.leader.env"
var zone3 = envFile + "3.leader.env"
var twoSeconds = delay(func() time.Duration {
return time.Second * 2
})
func Test_Round_AtLeader(t *testing.T) {
ctx, can := context.WithCancel(context.Background())
defer func() {
can()
<-ctx.Done()
registry.ShutDown()
<-time.After(2 * time.Second)
}()
runTest(t, ctx, zone1, singleRoundNumMessages, atLeaderOnly, randomInt)
}
func Test_Round_AtFollowers(t *testing.T) {
ctx, can := context.WithCancel(context.Background())
defer func() {
can()
<-ctx.Done()
registry.ShutDown()
<-time.After(2 * time.Second)
}()
runTest(t, ctx, zone1, singleRoundNumMessages, atFollowerOnly, randomInt)
}
func Test_Round_AtRandom(t *testing.T) {
ctx, can := context.WithCancel(context.Background())
defer func() {
can()
<-ctx.Done()
registry.ShutDown()
<-time.After(2 * time.Second)
}()
runTest(t, ctx, zone1, singleRoundNumMessages, atAny, randomInt)
}
func Test_Multiple_Rounds(t *testing.T) {
var numMessages = 16
ctx, can := context.WithCancel(context.Background())
defer func() {
can()
<-ctx.Done()
registry.ShutDown()
<-time.After(2 * time.Second)
}()
runTest(t, ctx, zone1, numMessages, atAny, twoSeconds)
}
func Test_Multiple_Zones(t *testing.T) {
ctx, can := context.WithCancel(context.Background())
defer func() {
can()
<-ctx.Done()
registry.ShutDown()
<-time.After(2 * time.Second)
}()
runTestZones(t, ctx, 2, atLeaderOnly, twoSeconds, []string{zone2, zone3}...)
}
// go test --v ./... -run Test_Round_AtLeader
// go test --v ./... -run Test_Round_AtFollowers
// go test --v ./... -run Test_Round_AtRandom
// go test --v ./... -run Test_Multiple_Rounds