forked from kedacore/keda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artemis.test.ts
112 lines (96 loc) · 3.54 KB
/
artemis.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
import * as fs from 'fs'
import * as sh from 'shelljs'
import * as tmp from 'tmp'
import test from 'ava'
import { ArtemisHelper } from './artemis-helpers'
import { createNamespace } from './helpers'
const testNamespace = 'kedartemis'
const artemisNamespace = 'artemis'
test.before(t => {
sh.config.silent = true
ArtemisHelper.installArtemis(t, artemisNamespace)
createNamespace("kedartemis")
ArtemisHelper.installArtemisSecret(t, testNamespace)
ArtemisHelper.installConsumer(t, testNamespace)
ArtemisHelper.publishMessages(t, testNamespace)
});
test.serial('Deployment should have 0 replicas on start', t => {
const replicaCount = sh.exec(`kubectl get deployment.apps/kedartemis-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`).stdout
t.log('replica count: %s', replicaCount);
t.is(replicaCount, '0', 'replica count should start out as 0')
})
test.serial(`Deployment should scale to 5 with 1000 messages on the queue then back to 0`, t => {
// deploy scaler
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, scaledObjectYaml)
t.is(
0,
sh.exec(`kubectl -n ${testNamespace} apply -f ${tmpFile.name}`).code, 'creating scaledObject should work.'
)
// with messages published, the consumer deployment should start receiving the messages
let replicaCount = '0'
for (let i = 0; i < 10 && replicaCount !== '5'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/kedartemis-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
t.log('replica count is:' + replicaCount)
if (replicaCount !== '5') {
sh.exec('sleep 5s')
}
}
t.is('5', replicaCount, 'Replica count should be 5 after 10 seconds')
for (let i = 0; i < 50 && replicaCount !== '0'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/kedartemis-consumer --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== '0') {
sh.exec('sleep 5s')
}
}
t.is('0', replicaCount, 'Replica count should be 0 after 3 minutes')
})
test.after.always.cb('clean up artemis deployment', t => {
sh.exec(`kubectl -n ${testNamespace} delete scaledobject.keda.sh/kedartemis-consumer-scaled-object`)
sh.exec(`kubectl -n ${testNamespace} delete triggerauthentications.sh/trigger-auth-kedartemis`)
ArtemisHelper.uninstallArtemis(t, artemisNamespace)
sh.exec(`kubectl delete namespace ${artemisNamespace}`)
ArtemisHelper.uninstallWorkloads(t, testNamespace)
sh.exec(`kubectl delete namespace ${testNamespace}`)
t.end()
})
const scaledObjectYaml=`
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: trigger-auth-kedartemis
spec:
secretTargetRef:
- parameter: username
name: kedartemis
key: artemis-username
- parameter: password
name: kedartemis
key: artemis-password
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: kedartemis-consumer-scaled-object
spec:
scaleTargetRef:
name: kedartemis-consumer
pollingInterval: 3 # Optional. Default: 30 seconds
cooldownPeriod: 10 # Optional. Default: 300 seconds
minReplicaCount: 0 # Optional. Default: 0
maxReplicaCount: 5 # Optional. Default: 100
triggers:
- type: artemis-queue
metadata:
managementEndpoint: "artemis-activemq.artemis:8161"
queueName: "test"
queueLength: "50"
brokerName: "artemis-activemq"
brokerAddress: "test"
authenticationRef:
name: trigger-auth-kedartemis
`