Skip to content

Commit

Permalink
feat: improve e2e tests reliability (#2942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Turrado Ferrero authored Apr 28, 2022
1 parent 9534660 commit 71a2ff9
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 165 deletions.
2 changes: 1 addition & 1 deletion tests/scalers/argo-rollouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.before(async t => {

// install argo-rollouts
createNamespace(argoRolloutsNamespace)
sh.exec(`curl -L https://raw.githubusercontent.com/argoproj/argo-rollouts/stable/manifests/install.yaml > ${argoRolloutsYamlFile.name}`)
sh.exec(`curl -L https://raw.githubusercontent.com/argoproj/argo-rollouts/v1.2.0/manifests/install.yaml > ${argoRolloutsYamlFile.name}`)
t.is(
0,
sh.exec(`kubectl apply -f ${argoRolloutsYamlFile.name} --namespace ${argoRolloutsNamespace}`).code,
Expand Down
13 changes: 0 additions & 13 deletions tests/scalers/influxdb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,11 @@ spec:
ports:
- containerPort: 8086
name: influxdb
volumeMounts:
- mountPath: /root/.influxdbv2
name: data
readinessProbe:
tcpSocket:
port: 8086
initialDelaySeconds: 5
periodSeconds: 10
volumeClaimTemplates:
- metadata:
name: data
namespace: influxdb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10G
---
apiVersion: v1
kind: Service
Expand Down
44 changes: 10 additions & 34 deletions tests/scalers/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as sh from 'shelljs'
import * as tmp from 'tmp'
import test from 'ava'
import { createNamespace } from './helpers'
import { createNamespace, waitForDeploymentReplicaCount } from './helpers'

const testNamespace = 'mysql-test'
const mySQLNamespace = 'mysql'
Expand Down Expand Up @@ -56,14 +56,11 @@ test.before(t => {

})

test.serial('Deployment should have 0 replicas on start', t => {
const replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
t.is(replicaCount, '0', 'replica count should start out as 0')
test.serial('Deployment should have 0 replicas on start', async t => {
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 60, 1000), 'replica count should start out as 0')
})

test.serial(`Deployment should scale to 5 (the max) then back to 0`, t => {
test.serial(`Deployment should scale to 2 (the max) then back to 0`, async t => {
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, insertRecordsJobYaml)
t.is(
Expand All @@ -72,31 +69,10 @@ test.serial(`Deployment should scale to 5 (the max) then back to 0`, t => {
'creating job should work.'
)

let replicaCount = '0'
const maxReplicaCount = 2
t.true(await waitForDeploymentReplicaCount(maxReplicaCount, deploymentName, testNamespace, 120, 1000), 'Replica count should be 0 after 2 minutes')

const maxReplicaCount = '5'

for (let i = 0; i < 60 && replicaCount !== maxReplicaCount; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== maxReplicaCount) {
sh.exec('sleep 2s')
}
}

t.is(maxReplicaCount, replicaCount, `Replica count should be ${maxReplicaCount} after 120 seconds`)

for (let i = 0; i < 36 && replicaCount !== '0'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== '0') {
sh.exec('sleep 5s')
}
}

t.is('0', replicaCount, 'Replica count should be 0 after 3 minutes')
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 360, 1000), 'Replica count should be 0 after 5 minutes')
})

test.after.always.cb('clean up mysql deployment', t => {
Expand Down Expand Up @@ -145,7 +121,7 @@ spec:
- update
env:
- name: TASK_INSTANCES_COUNT
value: "10000"
value: "4000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -180,7 +156,7 @@ spec:
pollingInterval: 5
cooldownPeriod: 10
minReplicaCount: 0
maxReplicaCount: 5
maxReplicaCount: 2
triggers:
- type: mysql
metadata:
Expand Down Expand Up @@ -210,7 +186,7 @@ spec:
- insert
env:
- name: TASK_INSTANCES_COUNT
value: "2000"
value: "4000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down
59 changes: 18 additions & 41 deletions tests/scalers/postgresql-hashicorp-vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as sh from 'shelljs'
import * as tmp from 'tmp'
import test from 'ava'
import { createNamespace } from './helpers'
import { createNamespace, waitForDeploymentReplicaCount } from './helpers'

const testNamespace = 'postgresql-hashicorp-vault'
const postgreSQLUsername = 'test-user'
Expand Down Expand Up @@ -72,47 +72,24 @@ test.before(t => {
)
})

test.serial('Deployment should have 0 replicas on start', t => {
const replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
t.is(replicaCount, '0', 'replica count should start out as 0')
})

test.serial(`Deployment should scale to 5 (the max) then back to 0`, t => {
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, insertRecordsJobYaml)
t.is(
0,
sh.exec(`kubectl apply -f ${tmpFile.name} --namespace ${testNamespace}`).code,
'creating job should work.'
)
test.serial('Deployment should have 0 replicas on start', async t => {
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 60, 1000), 'replica count should start out as 0')

let replicaCount = '0'

const maxReplicaCount = '5'

for (let i = 0; i < 30 && replicaCount !== maxReplicaCount; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== maxReplicaCount) {
sh.exec('sleep 2s')
}
}
})

t.is(maxReplicaCount, replicaCount, `Replica count should be ${maxReplicaCount} after 60 seconds`)
test.serial(`Deployment should scale to 2 (the max) then back to 0`, async t => {
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, insertRecordsJobYaml)
t.is(
0,
sh.exec(`kubectl apply -f ${tmpFile.name} --namespace ${testNamespace}`).code,
'creating job should work.'
)

for (let i = 0; i < 36 && replicaCount !== '0'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== '0') {
sh.exec('sleep 5s')
}
}
const maxReplicaCount = 2
t.true(await waitForDeploymentReplicaCount(maxReplicaCount, deploymentName, testNamespace, 120, 1000), 'Replica count should be 0 after 2 minutes')

t.is('0', replicaCount, 'Replica count should be 0 after 3 minutes')
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 360, 1000), 'Replica count should be 0 after 5 minutes')
})

test.after.always.cb('clean up postgresql deployment', t => {
Expand Down Expand Up @@ -163,7 +140,7 @@ spec:
- update
env:
- name: TASK_INSTANCES_COUNT
value: "10000"
value: "6000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -203,7 +180,7 @@ spec:
pollingInterval: 5
cooldownPeriod: 10
minReplicaCount: 0
maxReplicaCount: 5
maxReplicaCount: 2
triggers:
- type: postgresql
metadata:
Expand Down Expand Up @@ -233,7 +210,7 @@ spec:
- insert
env:
- name: TASK_INSTANCES_COUNT
value: "10000"
value: "6000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down
45 changes: 11 additions & 34 deletions tests/scalers/postgresql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as sh from 'shelljs'
import * as tmp from 'tmp'
import test from 'ava'
import { createNamespace } from './helpers'
import { createNamespace, waitForDeploymentReplicaCount } from './helpers'

const testNamespace = 'postgresql-test'
const postgreSQLNamespace = 'postgresql'
Expand Down Expand Up @@ -50,14 +50,12 @@ test.before(t => {
)
})

test.serial('Deployment should have 0 replicas on start', t => {
const replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
t.is(replicaCount, '0', 'replica count should start out as 0')
test.serial('Deployment should have 0 replicas on start', async t => {
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 60, 1000), 'replica count should start out as 0')

})

test.serial(`Deployment should scale to 5 (the max) then back to 0`, t => {
test.serial(`Deployment should scale to 2 (the max) then back to 0`, async t => {
const tmpFile = tmp.fileSync()
fs.writeFileSync(tmpFile.name, insertRecordsJobYaml)
t.is(
Expand All @@ -66,31 +64,10 @@ test.serial(`Deployment should scale to 5 (the max) then back to 0`, t => {
'creating job should work.'
)

let replicaCount = '0'

const maxReplicaCount = '5'

for (let i = 0; i < 30 && replicaCount !== maxReplicaCount; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== maxReplicaCount) {
sh.exec('sleep 2s')
}
}

t.is(maxReplicaCount, replicaCount, `Replica count should be ${maxReplicaCount} after 60 seconds`)

for (let i = 0; i < 36 && replicaCount !== '0'; i++) {
replicaCount = sh.exec(
`kubectl get deployment.apps/${deploymentName} --namespace ${testNamespace} -o jsonpath="{.spec.replicas}"`
).stdout
if (replicaCount !== '0') {
sh.exec('sleep 5s')
}
}
const maxReplicaCount = 2
t.true(await waitForDeploymentReplicaCount(maxReplicaCount, deploymentName, testNamespace, 120, 1000), 'Replica count should be 0 after 2 minutes')

t.is('0', replicaCount, 'Replica count should be 0 after 3 minutes')
t.true(await waitForDeploymentReplicaCount(0, deploymentName, testNamespace, 360, 1000), 'Replica count should be 0 after 5 minutes')
})

test.after.always.cb('clean up postgresql deployment', t => {
Expand Down Expand Up @@ -139,7 +116,7 @@ spec:
- update
env:
- name: TASK_INSTANCES_COUNT
value: "10000"
value: "6000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -174,7 +151,7 @@ spec:
pollingInterval: 5
cooldownPeriod: 10
minReplicaCount: 0
maxReplicaCount: 5
maxReplicaCount: 2
triggers:
- type: postgresql
metadata:
Expand Down Expand Up @@ -204,7 +181,7 @@ spec:
- insert
env:
- name: TASK_INSTANCES_COUNT
value: "10000"
value: "6000"
- name: CONNECTION_STRING
valueFrom:
secretKeyRef:
Expand Down
Loading

0 comments on commit 71a2ff9

Please sign in to comment.