Skip to content

Commit

Permalink
fix e2e tests for ensuring paused replicas dont scale
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed May 9, 2022
1 parent 3c630e0 commit 81bcddf
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions tests/scalers/azure-queue-pause.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ test.serial(
)

test.serial.cb(
'deployment should remain at pausedreplicacount (0) even with messages on storage',
'Deployment should remain at pausedReplicaCount (0) even with messages on storage',
t => {
const queuesvc = azure.createqueueservice(connectionstring)
queuesvc.messageencoder = new azure.queuemessageencoder.textbase64queuemessageencoder()
async.maplimit(
array(1000).keys(),
const queueSvc = azure.createQueueService(connectionString)
queueSvc.messageEncoder = new azure.QueueMessageEncoder.TextBase64QueueMessageEncoder()
async.mapLimit(
Array(1000).keys(),
20,
(n, cb) => queuesvc.createmessage(queuename, `test ${n}`, cb),
(n, cb) => queueSvc.createMessage(queueName, `test ${n}`, cb),
async () => {
// scaling is paused even with messages in storage.
t.true(await waitfordeploymentreplicacount(0, 'test-deployment', testnamespace, 60, 1000), 'replica count should remain 0 after 1 minute')
queuesvc.clearmessages(queuename, _ => {})
t.true(await checkIfReplicaCountGreater(0, 'test-deployment', testNamespace, 60, 1000), 'replica count remain 0 after 1 minute')
queueSvc.clearMessages(queueName, _ => {})
t.end()
}
)
Expand Down Expand Up @@ -137,6 +136,24 @@ test.after.always.cb('clean up workload test related deployments', t => {
t.end()
})


// checks if the current replica count is greater than the given target count for a given interval.
// returns false if it is greater, otherwise true.
async function checkIfReplicaCountGreater(target: number, name: string, namespace: string, iterations = 10, interval = 3000): Promise<boolean> {
for (let i = 0; i < iterations; i++) {
let replicaCountStr = sh.exec(`kubectl get deployment.apps/${name} --namespace ${namespace} -o jsonpath="{.spec.replicas}"`).stdout
try {
const replicaCount = parseInt(replicaCountStr, 10)
if (replicaCount > target) {
return false
}
} catch { }

await sleep(interval)
}
return true
}

const deployYaml = `apiVersion: v1
kind: Secret
metadata:
Expand Down

0 comments on commit 81bcddf

Please sign in to comment.