-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster_test.go
113 lines (106 loc) · 2.87 KB
/
cluster_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// +build !race
// by default we are using single HTTP client, so in cluster mode client is one per vm, in tests for multiple nodes that will race
// otherwise, when creating multiple transports default client will leak goroutines!
package loaderbot
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestCommonClusterClient(t *testing.T) {
s1 := RunService("localhost:50051")
defer s1.GracefulStop()
s2 := RunService("localhost:50052")
defer s2.GracefulStop()
s3 := RunService("localhost:50053")
defer s3.GracefulStop()
s4 := RunService("localhost:50054")
defer s4.GracefulStop()
time.Sleep(1 * time.Second)
c := NewClusterClient(&RunnerConfig{
TargetUrl: "https://clients5.google.com/pagead/drt/dn/",
Name: "test_runner",
SystemMode: BoundRPS,
InstanceType: "HTTPAttackerExample",
Attackers: 100,
AttackerTimeout: 1,
StartRPS: 100,
StepDurationSec: 5,
StepRPS: 20,
TestTimeSec: 10,
LogEncoding: "console",
LogLevel: "info",
ReportOptions: &ReportOptions{
CSV: true,
PNG: true,
Stream: true,
},
ClusterOptions: &ClusterOptions{
Nodes: []string{"localhost:50051", "localhost:50052", "localhost:50053", "localhost:50054"},
},
})
c.Run()
require.Equal(t, false, c.failed)
}
func TestCommonClusterShutdownOnError(t *testing.T) {
s1 := RunService("localhost:50055")
defer s1.GracefulStop()
s2 := RunService("localhost:50056")
defer s2.GracefulStop()
time.Sleep(1 * time.Second)
c := NewClusterClient(&RunnerConfig{
TargetUrl: "",
Name: "test_runner",
InstanceType: "HTTPAttackerExample",
SystemMode: BoundRPS,
Attackers: 10,
AttackerTimeout: 1,
StartRPS: 10,
StepDurationSec: 2,
StepRPS: 20,
TestTimeSec: 6,
SuccessRatio: 1,
LogEncoding: "console",
LogLevel: "info",
ReportOptions: &ReportOptions{
Stream: true,
},
ClusterOptions: &ClusterOptions{
Nodes: []string{"localhost:50055", "localhost:50056"},
},
})
c.Run()
require.Equal(t, true, c.failed)
}
func TestCommonClusterNodeIsBusy(t *testing.T) {
s1 := RunService("localhost:50057")
defer s1.GracefulStop()
time.Sleep(1 * time.Second)
cfg := &RunnerConfig{
TargetUrl: "https://clients5.google.com/pagead/drt/dn/",
Name: "test_runner",
InstanceType: "HTTPAttackerExample",
SystemMode: BoundRPS,
Attackers: 10,
AttackerTimeout: 1,
StartRPS: 100,
StepDurationSec: 5,
StepRPS: 20,
TestTimeSec: 2,
LogEncoding: "console",
LogLevel: "info",
ReportOptions: &ReportOptions{
CSV: true,
PNG: true,
Stream: true,
},
ClusterOptions: &ClusterOptions{
Nodes: []string{"localhost:50057"},
},
}
c := NewClusterClient(cfg)
go c.Run()
time.Sleep(1 * time.Second)
c2 := NewClusterClient(cfg)
require.True(t, c2.failed)
}