diff --git a/tests/scalers/external-scaler.sj.test.ts b/tests/scalers/external-scaler.sj.test.ts index 5a5586ddc10..d204d888015 100644 --- a/tests/scalers/external-scaler.sj.test.ts +++ b/tests/scalers/external-scaler.sj.test.ts @@ -50,7 +50,7 @@ test.serial("Deployment should scale up to maxReplicaCount", async t => { "Modifying scaled job should work" ) - t.true(await waitForJobCount(maxReplicaCount, testNamespace, 60, 1000),`Replica count should be 0 after 1 minute`) + t.true(await waitForJobCount(maxReplicaCount, testNamespace, 60, 1000),`Replica count should be ${maxReplicaCount} after 1 minute`) }) test.serial("Deployment should scale back down to 0", async t => { diff --git a/tests/scalers/helpers.ts b/tests/scalers/helpers.ts index bbf796e86d2..8d80c37b9d3 100644 --- a/tests/scalers/helpers.ts +++ b/tests/scalers/helpers.ts @@ -29,7 +29,12 @@ export async function waitForJobCount(target: number, namespace: string, iterati for (let i = 0; i < iterations; i++) { let jobCountStr = sh.exec(`kubectl get job --namespace ${namespace} | wc -l`).stdout.replace(/[\r\n]/g,"") try { - const jobCount = parseInt(jobCountStr, 10) + let jobCount = parseInt(jobCountStr, 10) + // This method counts also the header line in the output, so we have to remove 1 if the jobCount is > 1 + if (jobCount > 0) { + jobCount-- + } + if (jobCount === target) { return true } diff --git a/tests/scalers/mongodb.test.ts b/tests/scalers/mongodb.test.ts index c76ddb317b0..15f33a065b5 100644 --- a/tests/scalers/mongodb.test.ts +++ b/tests/scalers/mongodb.test.ts @@ -83,10 +83,7 @@ test.serial(`Job should scale to 5 then back to 0`, async t => { 'insert 5 mongo record' ) - // maxJobCount = real Job + first line of output - const maxJobCount = 6 - - t.true(await waitForJobCount(maxJobCount, testNamespace, 60, 1000), `Job count should be ${maxJobCount} after 60 seconds`) + t.true(await waitForJobCount(5, testNamespace, 60, 1000), `Job count should be ${maxJobCount} after 60 seconds`) // Process elements