@@ -21,16 +21,18 @@ const (
21
21
)
22
22
23
23
var (
24
- testNamespace = fmt .Sprintf ("%s-ns" , testName )
25
- deploymentName = fmt .Sprintf ("%s-consumer-deployment" , testName )
26
- jobName = fmt .Sprintf ("%s-producer-job" , testName )
27
- scaledObjectName = fmt .Sprintf ("%s-so" , testName )
28
- nsqNamespace = "nsq"
29
- nsqHelmRepoURL = "https://nsqio.github.io/helm-chart"
30
- minReplicas = 1
31
- maxReplicas = 10
32
- topicName = "test_topic"
33
- channelName = "test_channel"
24
+ testNamespace = fmt .Sprintf ("%s-ns" , testName )
25
+ deploymentName = fmt .Sprintf ("%s-consumer-deployment" , testName )
26
+ jobName = fmt .Sprintf ("%s-producer-job" , testName )
27
+ scaledObjectName = fmt .Sprintf ("%s-so" , testName )
28
+ nsqNamespace = "nsq"
29
+ nsqHelmRepoURL = "https://nsqio.github.io/helm-chart"
30
+ minReplicaCount = 0
31
+ maxReplicaCount = 2
32
+ depthThreshold = 10
33
+ activationDepthThreshold = 5
34
+ topicName = "test_topic"
35
+ channelName = "test_channel"
34
36
)
35
37
36
38
const (
58
60
- "--mode=consumer"
59
61
- "--topic={{.TopicName}}"
60
62
- "--channel={{.ChannelName}}"
63
+ - "--sleep-duration=1s"
61
64
- "--nsqlookupd-http-address=nsq-nsqlookupd.{{.NSQNamespace}}.svc.cluster.local:4161"
62
65
imagePullPolicy: Always
63
66
`
@@ -73,9 +76,8 @@ metadata:
73
76
spec:
74
77
pollingInterval: 5
75
78
cooldownPeriod: 10
76
- idleReplicaCount: 0
77
- maxReplicaCount: {{.MaxReplicas}}
78
- minReplicaCount: {{.MinReplicas}}
79
+ maxReplicaCount: {{.MaxReplicaCount}}
80
+ minReplicaCount: {{.MinReplicaCount}}
79
81
scaleTargetRef:
80
82
apiVersion: "apps/v1"
81
83
kind: "Deployment"
87
89
nsqLookupdHTTPAddresses: "nsq-nsqlookupd.{{.NSQNamespace}}.svc.cluster.local:4161"
88
90
topic: "{{.TopicName}}"
89
91
channel: "{{.ChannelName}}"
90
- depthThreshold: "10 "
91
- activationDepthThreshold: "5 "
92
+ depthThreshold: "{{.DepthThreshold}} "
93
+ activationDepthThreshold: "{{.ActivationDepthThreshold}} "
92
94
`
93
95
94
96
jobTemplate = `
@@ -114,16 +116,18 @@ spec:
114
116
)
115
117
116
118
type templateData struct {
117
- TestNamespace string
118
- NSQNamespace string
119
- DeploymentName string
120
- ScaledObjectName string
121
- JobName string
122
- MinReplicas int
123
- MaxReplicas int
124
- TopicName string
125
- ChannelName string
126
- MessageCount int
119
+ TestNamespace string
120
+ NSQNamespace string
121
+ DeploymentName string
122
+ ScaledObjectName string
123
+ JobName string
124
+ MinReplicaCount int
125
+ MaxReplicaCount int
126
+ DepthThreshold int
127
+ ActivationDepthThreshold int
128
+ TopicName string
129
+ ChannelName string
130
+ MessageCount int
127
131
}
128
132
129
133
func TestNSQScaler (t * testing.T ) {
@@ -172,15 +176,17 @@ func uninstallNSQ(t *testing.T) {
172
176
173
177
func getTemplateData () (templateData , []Template ) {
174
178
return templateData {
175
- TestNamespace : testNamespace ,
176
- NSQNamespace : nsqNamespace ,
177
- DeploymentName : deploymentName ,
178
- JobName : jobName ,
179
- ScaledObjectName : scaledObjectName ,
180
- MinReplicas : minReplicas ,
181
- MaxReplicas : maxReplicas ,
182
- TopicName : topicName ,
183
- ChannelName : channelName ,
179
+ TestNamespace : testNamespace ,
180
+ NSQNamespace : nsqNamespace ,
181
+ DeploymentName : deploymentName ,
182
+ JobName : jobName ,
183
+ ScaledObjectName : scaledObjectName ,
184
+ MinReplicaCount : minReplicaCount ,
185
+ MaxReplicaCount : maxReplicaCount ,
186
+ TopicName : topicName ,
187
+ ChannelName : channelName ,
188
+ DepthThreshold : depthThreshold ,
189
+ ActivationDepthThreshold : activationDepthThreshold ,
184
190
}, []Template {
185
191
{Name : "deploymentTemplate" , Config : deploymentTemplate },
186
192
{Name : "scaledObjectTemplate" , Config : scaledObjectTemplate },
@@ -190,20 +196,25 @@ func getTemplateData() (templateData, []Template) {
190
196
func testActivation (t * testing.T , kc * kubernetes.Clientset , data templateData ) {
191
197
t .Log ("--- testing activation ---" )
192
198
193
- data .MessageCount = 5
199
+ data .MessageCount = activationDepthThreshold
194
200
KubectlReplaceWithTemplate (t , data , "jobTemplate" , jobTemplate )
195
-
196
201
AssertReplicaCountNotChangeDuringTimePeriod (t , kc , deploymentName , testNamespace , 0 , 60 )
202
+
203
+ data .MessageCount = 1 // total message count > activationDepthThreshold
204
+ KubectlReplaceWithTemplate (t , data , "jobTemplate" , jobTemplate )
205
+ require .True (t , WaitForDeploymentReplicaReadyCount (t , kc , deploymentName , testNamespace , 1 , 60 , 1 ),
206
+ "replica count should reach 1 in under 1 minute" )
197
207
}
198
208
199
209
func testScaleOut (t * testing.T , kc * kubernetes.Clientset , data templateData ) {
200
210
t .Log ("--- testing scale out ---" )
201
211
202
- data .MessageCount = 1 // 5 already published + 1 > activationDepthThreshold
212
+ // can handle depthThreshold messages per replica - using maxReplicaCount + 1 to ensure scaling to maxReplicaCount
213
+ data .MessageCount = depthThreshold * (maxReplicaCount + 1 )
203
214
KubectlReplaceWithTemplate (t , data , "jobTemplate" , jobTemplate )
204
215
205
- require .True (t , WaitForDeploymentReplicaReadyCount (t , kc , deploymentName , testNamespace , 1 , 60 , 1 ),
206
- "replica count should be 1 after 1 minute" )
216
+ require .True (t , WaitForDeploymentReplicaReadyCount (t , kc , deploymentName , testNamespace , maxReplicaCount , 60 , 1 ),
217
+ "replica count should reach 2 in under 1 minute" )
207
218
}
208
219
209
220
func testScaleIn (t * testing.T , kc * kubernetes.Clientset ) {
0 commit comments