Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K6 floating point test visa #6356

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion k6/models/initalize-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class InitializePaymentModel {
paymentId,
maxTimeoutAttempts,
minPassRatePercentage,
amount,
) {
// reset db
resetPage.resetDB(resetScript);
Expand All @@ -33,7 +34,7 @@ export default class InitializePaymentModel {
// Change status of all PAs to included and check response
programsPage.updateRegistrationStatusAndLog(programId, 'included');

paymentsPage.createPayment(programId);
paymentsPage.createPayment(programId, amount);
// Monitor that 10% of payments is successful and then stop the test
return paymentsPage.getPaymentResults(
programId,
Expand Down
4 changes: 2 additions & 2 deletions k6/models/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const { baseUrl } = config;

export default class paymentsModel {
constructor() {}
createPayment(programId) {
createPayment(programId, amount) {
const url = `${baseUrl}api/programs/${programId}/payments`;
const payload = JSON.stringify({
payment: 3,
amount: 10,
amount,
});
const params = {
headers: {
Expand Down
2 changes: 2 additions & 0 deletions k6/tests/payment100kRegistrationOCW.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const programId = 3;
const paymentId = 3;
const maxTimeoutAttempts = 200;
const minPassRatePercentage = 10;
const amount = 11.11; // Using an amount with cents. To ensure we handle javascript floating point precision issues

export const options = {
thresholds: {
Expand All @@ -30,6 +31,7 @@ export default function () {
paymentId,
maxTimeoutAttempts,
minPassRatePercentage,
amount,
);
check(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
Expand Down
2 changes: 2 additions & 0 deletions k6/tests/payment100kRegistrationSafaricom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const programId = 1;
const paymentId = 3;
const maxTimeoutAttempts = 200;
const minPassRatePercentage = 10;
const amount = 10;

export const options = {
thresholds: {
Expand All @@ -30,6 +31,7 @@ export default function () {
paymentId,
maxTimeoutAttempts,
minPassRatePercentage,
amount,
);
check(monitorPayment, {
'Payment progressed successfully status 200': (r) => {
Expand Down
3 changes: 2 additions & 1 deletion k6/tests/performanceDuringPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const programId = 3;
const paymentId = 3;
const maxTimeoutAttempts = 400;
const minPassRatePercentage = 50;
const amount = 10;

export const options = {
thresholds: {
Expand Down Expand Up @@ -47,7 +48,7 @@ export default function () {
});

// Do the payment
const doPayment = paymentsPage.createPayment(programId);
const doPayment = paymentsPage.createPayment(programId, amount);
check(doPayment, {
'Payment successfully done status 202': (r) => {
if (r.status != 202) {
Expand Down
3 changes: 2 additions & 1 deletion k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const programId = 3;
const paymentId = 3;
const maxTimeoutAttempts = 400;
const minPassRatePercentage = 100;
const amount = 10;

export const options = {
vus: 1,
Expand Down Expand Up @@ -46,7 +47,7 @@ export default function () {
});

// Do the payment
const doPayment = paymentsPage.createPayment(programId);
const doPayment = paymentsPage.createPayment(programId, amount);
check(doPayment, {
'Payment successfully done status 202': (r) => {
if (r.status != 202) {
Expand Down
3 changes: 2 additions & 1 deletion k6/tests/statusChangePaymentInLargeProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const programId = 3;
const paymentId = 3;
const maxTimeoutAttempts = 200;
const minPassRatePercentage = 10;
const amount = 10;

export const options = {
thresholds: {
Expand Down Expand Up @@ -111,7 +112,7 @@ export default function () {
});

// Do the payment
const doPayment = paymentsPage.createPayment(programId);
const doPayment = paymentsPage.createPayment(programId, amount);
check(doPayment, {
'Payment successfully done status 202': (r) => {
if (r.status != 202) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InjectQueue } from '@nestjs/bull';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Queue } from 'bull';
import Redis from 'ioredis';

import { createRedisClient } from '@121-service/src/payments/redis/redis-client';
import { CreateMessageQueueNames } from '@121-service/src/queues-registry/enum/create-message-queue-names.enum';
Expand Down Expand Up @@ -120,9 +121,20 @@ export class QueuesRegistryService implements OnModuleInit {
const keysWithoutPrefix = keys.map((key) =>
key.replace(process.env.REDIS_PREFIX + ':', ''),
);
await redisClient.del(...keysWithoutPrefix);
await this.batchDeleteKeys(redisClient, keysWithoutPrefix);
}

await redisClient.keys(`${process.env.REDIS_PREFIX}:*`);
}

// This is prevent this error when deleting large amount of keys: RangeError: Maximum call stack size exceeded
private async batchDeleteKeys(
redisClient: Redis,
keys: string[],
batchSize = 1000,
): Promise<void> {
for (let i = 0; i < keys.length; i += batchSize) {
const batch = keys.slice(i, i + batchSize);
await redisClient.del(...batch);
}
}
}
Loading