Skip to content

Commit

Permalink
solve problems with job helper
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer committed May 13, 2022
1 parent c41a34c commit eb2d2df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/scalers/external-scaler.sj.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
7 changes: 6 additions & 1 deletion tests/scalers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions tests/scalers/mongodb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eb2d2df

Please sign in to comment.