Skip to content

Commit

Permalink
Revert the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrk39 committed Jan 23, 2025
1 parent 367a9a9 commit 97da8fc
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 37 deletions.
26 changes: 19 additions & 7 deletions k6/tests/getProgramWithManyAttributes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import { Counter } from 'k6/metrics';

import { registrationVisa } from '../helpers/registration-default.data.js';
import loginModel from '../models/login.js';
Expand All @@ -18,22 +19,33 @@ const programId = 2;
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
duration: '30s',
iterations: 1,
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

export default function () {
// reset db
const reset = resetPage.resetDB(resetScript);
check(reset, {
checkAndFail(reset, {
'Reset succesfull status was 202': (r) => r.status == 202,
});

// login
const login = loginPage.login();
check(login, {
checkAndFail(login, {
'Login succesfull status was 200': (r) => r.status == 201,
'Login time is less than 200ms': (r) => {
if (r.timings.duration >= 200) {
Expand All @@ -49,7 +61,7 @@ export default function () {
programsPage.createProgramRegistrationAttribute(programId, attributeName);
registrationVisa[attributeName] = 'bla';

check(programRegistrationAttributes, {
checkAndFail(programRegistrationAttributes, {
'Program registration attributes added successfully status was 201': (
r,
) => {
Expand All @@ -66,20 +78,20 @@ export default function () {
programId,
registrationVisa,
);
check(registrationImport, {
checkAndFail(registrationImport, {
'Import of registration successful status was 201': (r) => r.status == 201,
});

// Duplicate registration
const duplicateRegistration =
resetPage.duplicateRegistrations(duplicateNumber);
check(duplicateRegistration, {
checkAndFail(duplicateRegistration, {
'Duplication successful status was 201': (r) => r.status == 201,
});

// get program by id and validte load time is less than 200ms
const program = programsPage.getProgramById(2);
check(program, {
checkAndFail(program, {
'Programme loaded succesfully status was 200': (r) => r.status == 200,
'Programme load time is less than 200ms': (r) => {
if (r.timings.duration >= 200) {
Expand Down
20 changes: 16 additions & 4 deletions k6/tests/import1000Registrations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import { Counter } from 'k6/metrics';

import LoginModel from '../models/login.js';
import RegistrationsModel from '../models/registrations.js';
Expand All @@ -24,23 +25,34 @@ if (!csvFile) {
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
iterations: 1,
// REFACTOR: should we investigate if the duration can be reduced?
duration: '9m', // At the time of writing this test, this test took ~7m both locally and on GH actions. Setting the limit to 9m, so it's below the API timeout limit of10m. Change this value only deliberatedly. If the tests takes longer because of regression effects, it should fail.
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

export default function () {
// reset db
const reset = resetPage.resetDB(resetScript);
check(reset, {
checkAndFail(reset, {
'Reset successful status was 202': (r) => r.status == 202,
});

// login
const login = loginPage.login();
check(login, {
checkAndFail(login, {
'Login successful status was 200': (r) => r.status == 201,
'Login time is less than 200ms': (r) => {
if (r.timings.duration >= 200) {
Expand All @@ -55,7 +67,7 @@ export default function () {
programId,
csvFile,
);
check(registrationImport, {
checkAndFail(registrationImport, {
'Import of registration successful status was 201': (r) => r.status == 201,
});

Expand Down
16 changes: 14 additions & 2 deletions k6/tests/payment100kRegistrationOCW.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import { Counter } from 'k6/metrics';

import { registrationVisa } from '../helpers/registration-default.data.js';
import InitializePaymentModel from '../models/initalize-payment.js';
Expand All @@ -16,12 +17,23 @@ const amount = 11.11;
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
duration: '80m',
iterations: 1,
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

export default function () {
const monitorPayment = initializePayment.initializePayment(
resetScript,
Expand All @@ -33,7 +45,7 @@ export default function () {
minPassRatePercentage,
amount,
);
check(monitorPayment, {
checkAndFail(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
if (r.status != 200) {
const responseBody = JSON.parse(r.body);
Expand Down
16 changes: 14 additions & 2 deletions k6/tests/payment100kRegistrationSafaricom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import { Counter } from 'k6/metrics';

import { registrationSafaricom } from '../helpers/registration-default.data.js';
import InitializePaymentModel from '../models/initalize-payment.js';
Expand All @@ -16,12 +17,23 @@ const amount = 10;
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
duration: '80m',
iterations: 1,
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

export default function () {
const monitorPayment = initializePayment.initializePayment(
resetScript,
Expand All @@ -33,7 +45,7 @@ export default function () {
minPassRatePercentage,
amount,
);
check(monitorPayment, {
checkAndFail(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
if (r.status != 200) {
const responseBody = JSON.parse(r.body);
Expand Down
26 changes: 19 additions & 7 deletions k6/tests/performanceDuringPayment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import { Counter } from 'k6/metrics';

import loginModel from '../models/login.js';
import metricstsModel from '../models/metrics.js';
Expand All @@ -22,22 +23,33 @@ const amount = 11.11;
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
duration: '60m',
iterations: 1,
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

export default function () {
// reset db
const reset = resetPage.resetDBMockRegistrations(duplicateNumber);
check(reset, {
checkAndFail(reset, {
'Reset succesfull status was 202': (r) => r.status == 202,
});

// login
const login = loginPage.login();
check(login, {
checkAndFail(login, {
'Login succesfull status was 200': (r) => r.status == 201,
'Login time is less than 200ms': (r) => {
if (r.timings.duration >= 200) {
Expand All @@ -49,7 +61,7 @@ export default function () {

// Do the payment
const doPayment = paymentsPage.createPayment(programId, amount);
check(doPayment, {
checkAndFail(doPayment, {
'Payment successfully done status 202': (r) => {
if (r.status != 202) {
console.log(r.body);
Expand All @@ -67,7 +79,7 @@ export default function () {
minPassRatePercentage,
amount,
);
check(monitorPayment, {
checkAndFail(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
if (r.status != 200) {
const responseBody = JSON.parse(r.body);
Expand All @@ -79,13 +91,13 @@ export default function () {

// get export list
const exportList = metricsPage.getExportList(3);
check(exportList, {
checkAndFail(exportList, {
'Export list loaded succesfully status was 200': (r) => r.status == 200,
});

// send bulk message
const message = programsPage.sendBulkMessage(3);
check(message, {
checkAndFail(message, {
'Message sent succesfully status was 202': (r) => r.status == 202,
});

Expand Down
22 changes: 17 additions & 5 deletions k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { check, sleep } from 'k6';
import { check, fail, sleep } from 'k6';
import http from 'k6/http';
import { Counter } from 'k6/metrics';

import loginModel from '../models/login.js';
import paymentsModel from '../models/payments.js';
Expand All @@ -20,12 +21,23 @@ export const options = {
thresholds: {
// In this case the health check runs multiple times and so of the responses are going to be 500 before service is up
http_req_failed: ['rate<0.30'], // http errors should be less than 30%
failed_checks: ['count<1'], // fail the test if any check fails
},
vus: 1,
duration: '60m',
iterations: 1,
};

const failedChecks = new Counter('failed_checks');

function checkAndFail(response, checks) {
const result = check(response, checks);
if (!result) {
failedChecks.add(1);
fail('One or more checks failed');
}
}

function isServiceUp() {
const response = http.get('http://localhost:3000/api/health/health'); // Replace with your health check endpoint
return response.status === 200;
Expand All @@ -34,13 +46,13 @@ function isServiceUp() {
export default function () {
// reset db
const reset = resetPage.resetDBMockRegistrations(duplicateNumber);
check(reset, {
checkAndFail(reset, {
'Reset succesfull status was 202': (r) => r.status == 202,
});

// login
const login = loginPage.login();
check(login, {
checkAndFail(login, {
'Login succesfull status was 200': (r) => r.status == 201,
'Login time is less than 200ms': (r) => {
if (r.timings.duration >= 200) {
Expand All @@ -52,7 +64,7 @@ export default function () {

// Do the payment
const doPayment = paymentsPage.createPayment(programId, amount);
check(doPayment, {
checkAndFail(doPayment, {
'Payment successfully done status 202': (r) => {
if (r.status != 202) {
console.log(r.body);
Expand Down Expand Up @@ -80,7 +92,7 @@ export default function () {
duplicateNumber,
minPassRatePercentage,
);
check(monitorPayment, {
checkAndFail(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
if (r.status != 200) {
const responseBody = JSON.parse(r.body);
Expand Down
Loading

0 comments on commit 97da8fc

Please sign in to comment.