-
Notifications
You must be signed in to change notification settings - Fork 1k
/
solace.test.ts
143 lines (121 loc) · 4.93 KB
/
solace.test.ts
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as sh from 'shelljs'
import test from 'ava'
import { SolaceHelper } from './solace-helpers'
const testNamespace = 'solace'
const queueName = 'test'
test.before(t => {
sh.config.silent = true
SolaceHelper.getUpdateSolaceHelmChart(t)
SolaceHelper.installSolaceBroker(t, testNamespace)
SolaceHelper.installSolaceTestHelper(t, testNamespace)
SolaceHelper.configSolacePubSubBroker(t, testNamespace)
SolaceHelper.installSolaceConsumer(t)
});
test.serial('#1 Consumer Deployment should have 1 replicas on start', t => {
let replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('replica count: ' + replicas);
t.is(replicas, '1', 'replica count should start out as 1')
})
test.serial('#2 Create Scaled Object; Consumer Deployment replicas scale to zero', t => {
// deploy scaler and auth objects
SolaceHelper.installSolaceKedaSecret(t)
SolaceHelper.installSolaceKedaTriggerAuth(t)
SolaceHelper.installSolaceKedaScaledObject(t)
let replicas = '1'
let success = false
for (let i = 0; i <= 20 && replicas !== '10'; i++) {
replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('pod replicas (of 0 expected): ' + replicas)
if (replicas !== '0') {
sh.exec('sleep 3s')
} else {
t.log('scale to zero goal met')
success = true
break
}
}
t.is('0', replicas, 'replica count should be 0 after 60 seconds')
if (success) {
sh.exec('sleep 5s')
}
})
test.serial('#3 Publish 400 messages to Consumer Queue; Scale Replicas to 10 for message count', t => {
// publish messages to queue -- 400 msgs at 50 msgs/sec
SolaceHelper.publishMessages(t, testNamespace, '50', '400', '256')
// with messages published, the consumer deployment should start receiving the messages
let replicas = '0'
for (let i = 0; i < 30 && replicas !== '10'; i++) {
replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('pod replicas (of 10 expected): ' + replicas)
if (replicas !== '10') {
sh.exec('sleep 2s')
} else {
t.log('max pod replica count goal met - msg count')
break
}
}
t.is('10', replicas, 'replica count should be 10 after 60 seconds - msg count')
})
test.serial('#4 Consumer Deployment scales to zero replicas after all messages read', t => {
let replicas = '10'
let success = false
// Replicas should decrease as messages are consumed
for (let i = 0; i < 60 && replicas !== '0'; i++) {
replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('pod replicas (of 0 expected): ' + replicas)
if (replicas !== '0') {
sh.exec('sleep 5s')
} else {
t.log('min pod replica count goal met (scale to zero)')
success = true
break
}
}
t.is('0', replicas, 'replica count should be 0 after 5 minutes')
if (success) {
sh.exec('sleep 5s')
}
})
test.serial('#5 Publish 50 LARGE messages to Consumer Queue; Scale Replicas to 10 for spool usage', t => {
// publish messages to queue -- 400 msgs at 50 msgs/sec
SolaceHelper.publishMessages(t, testNamespace, '10', '50', '4194304')
// with messages published, the consumer deployment should start receiving the messages
let replicas = '0'
for (let i = 0; i < 30 && replicas !== '10'; i++) {
replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('pod replicas (of 10 expected): ' + replicas)
if (replicas !== '10') {
sh.exec('sleep 2s')
} else {
t.log('max pod replica count goal met - spool size')
break
}
}
t.is('10', replicas, 'replica count should be 10 after 60 seconds - spool size')
})
test.serial('#6 Consumer Deployment scales to zero replicas after all messages read', t => {
let replicas = '10'
let success = false
// Replicas should decrease as messages are consumed
for (let i = 0; i < 60 && replicas !== '0'; i++) {
replicas = sh.exec(`kubectl get deployment.apps/solace-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('pod replicas (of 0 expected): ' + replicas)
if (replicas !== '0') {
sh.exec('sleep 5s')
} else {
t.log('min pod replica count goal met (scale to zero)')
success = true
break
}
}
t.is('0', replicas, 'Replica count should be 0 after 5 minutes')
if (success) {
sh.exec('sleep 5s')
}
})
test.after.always.cb('clean up the cluster', t => {
SolaceHelper.uninstallSolaceKedaObjects(t)
SolaceHelper.uninstallSolaceTestPods(t)
SolaceHelper.uninstallSolace(t, testNamespace)
t.end()
})