Skip to content

Commit

Permalink
update e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Jinli Liang <paul.liang@rokt.com>
  • Loading branch information
PaulLiang1 committed Jan 11, 2022
1 parent 329c8bd commit 41d7ad2
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/scalers/kafka.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,33 @@ test.serial('Applying ScaledObject with multiple topics should scale up pods', t
'Deploying Scaled Object should work.'
)
sh.exec(`sleep 5s`)
waitForReplicaCount(1, commandToCheckReplicas)
t.is('0', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 0.')

// produce a single msg to the default topic should not scale
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 20s`)
// when lag is 0, scaled object is not active, replica = 0
waitForReplicaCount(0, commandToCheckReplicas)
t.is('0', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 0.')

// produce one more msg to the different topic should trigger scale
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic2}'`)
sh.exec(`sleep 20s`)
// produce a single msg to the default topic
// should turn scale object active, replica = 1
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(1, commandToCheckReplicas)
t.is('1', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 1.')

// produce one more msg to the different topic within the same group
// will turn total consumer group lag to 2.
// with lagThreshold as 1 -> making hpa AverageValue to 1
// this should turn nb of replicas to 2
// as desiredReplicaCount = totalLag / avgThreshold
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic2}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(2, commandToCheckReplicas)
t.is('2', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 2.')

// make it 3 cause why not?
sh.exec(`kubectl exec --namespace ${defaultNamespace} ${defaultKafkaClient} -- sh -exc 'echo "{\"text\": \"foo\"}" | kafka-console-producer --broker-list ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092 --topic ${defaultTopic}'`)
sh.exec(`sleep 5s`)
waitForReplicaCount(3, commandToCheckReplicas)
t.is('3', sh.exec(commandToCheckReplicas).stdout, 'Replica count should be 3.')
})

test.serial('Cleanup after multiple topics test', t=> {
Expand Down Expand Up @@ -481,5 +494,5 @@ spec:
metadata:
bootstrapServers: ${defaultCluster}-kafka-bootstrap.${defaultNamespace}:9092
consumerGroup: multiTopic
lagThreshold: '2'
lagThreshold: '1'
offsetResetPolicy: 'latest'`

0 comments on commit 41d7ad2

Please # to comment.