From bfa8ea727bae107936c833d5e4c3b2c8513338d2 Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 7 Jan 2025 11:27:27 +0100 Subject: [PATCH 1/4] K6 floating point test visa --- k6/models/initalize-payment.js | 3 ++- k6/models/payments.js | 4 ++-- k6/tests/payment100kRegistrationOCW.js | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/k6/models/initalize-payment.js b/k6/models/initalize-payment.js index babe900934..03dd48220c 100644 --- a/k6/models/initalize-payment.js +++ b/k6/models/initalize-payment.js @@ -21,6 +21,7 @@ export default class InitializePaymentModel { paymentId, maxTimeoutAttempts, minPassRatePercentage, + amount, ) { // reset db resetPage.resetDB(resetScript); @@ -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, diff --git a/k6/models/payments.js b/k6/models/payments.js index db7f8aaf1c..94ea7f5187 100644 --- a/k6/models/payments.js +++ b/k6/models/payments.js @@ -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: { diff --git a/k6/tests/payment100kRegistrationOCW.js b/k6/tests/payment100kRegistrationOCW.js index 41eface75d..6cbfcb7e09 100644 --- a/k6/tests/payment100kRegistrationOCW.js +++ b/k6/tests/payment100kRegistrationOCW.js @@ -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: { @@ -30,6 +31,7 @@ export default function () { paymentId, maxTimeoutAttempts, minPassRatePercentage, + amount, ); check(monitorPayment, { 'Payment progressed successfully status 200': (r) => { From 90d8b8d648e786a75c8c79cefae819b62d10bfa2 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 9 Jan 2025 11:28:27 +0100 Subject: [PATCH 2/4] Fix amount in performanceDuringPayment & empty queue in batches --- k6/tests/performanceDuringPayment.js | 3 ++- .../queues-registry/queues-registry.service.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/k6/tests/performanceDuringPayment.js b/k6/tests/performanceDuringPayment.js index 099b361648..980b48168f 100644 --- a/k6/tests/performanceDuringPayment.js +++ b/k6/tests/performanceDuringPayment.js @@ -17,6 +17,7 @@ const programId = 3; const paymentId = 3; const maxTimeoutAttempts = 400; const minPassRatePercentage = 50; +const amount = 10; export const options = { thresholds: { @@ -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) { diff --git a/services/121-service/src/queues-registry/queues-registry.service.ts b/services/121-service/src/queues-registry/queues-registry.service.ts index 98ca45bb7e..12e603529a 100644 --- a/services/121-service/src/queues-registry/queues-registry.service.ts +++ b/services/121-service/src/queues-registry/queues-registry.service.ts @@ -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'; @@ -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 { + for (let i = 0; i < keys.length; i += batchSize) { + const batch = keys.slice(i, i + batchSize); + await redisClient.del(...batch); + } + } } From a6a5b61c201b17aca4a8ac4dabc83c28b85a9e20 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 9 Jan 2025 16:28:35 +0100 Subject: [PATCH 3/4] initiate payment safaricom amount --- k6/tests/payment100kRegistrationSafaricom.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k6/tests/payment100kRegistrationSafaricom.js b/k6/tests/payment100kRegistrationSafaricom.js index 90504ce79d..9f83f6d196 100644 --- a/k6/tests/payment100kRegistrationSafaricom.js +++ b/k6/tests/payment100kRegistrationSafaricom.js @@ -11,6 +11,7 @@ const programId = 1; const paymentId = 3; const maxTimeoutAttempts = 200; const minPassRatePercentage = 10; +const amount = 10; export const options = { thresholds: { @@ -30,6 +31,7 @@ export default function () { paymentId, maxTimeoutAttempts, minPassRatePercentage, + amount, ); check(monitorPayment, { 'Payment progressed successfully status 200': (r) => { From 6c3325108bb5a4ed9f120d88840f482b349ce4fb Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 10 Jan 2025 12:17:56 +0100 Subject: [PATCH 4/4] fix k6 amounts --- k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js | 3 ++- k6/tests/statusChangePaymentInLargeProgram.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js b/k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js index 83184b89e4..11def767b9 100644 --- a/k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js +++ b/k6/tests/retryFailedJobsOnStartupDuringQueueProcessing.js @@ -14,6 +14,7 @@ const programId = 3; const paymentId = 3; const maxTimeoutAttempts = 400; const minPassRatePercentage = 100; +const amount = 10; export const options = { vus: 1, @@ -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) { diff --git a/k6/tests/statusChangePaymentInLargeProgram.js b/k6/tests/statusChangePaymentInLargeProgram.js index 606c27fb13..3068a3b9dd 100644 --- a/k6/tests/statusChangePaymentInLargeProgram.js +++ b/k6/tests/statusChangePaymentInLargeProgram.js @@ -19,6 +19,7 @@ const programId = 3; const paymentId = 3; const maxTimeoutAttempts = 200; const minPassRatePercentage = 10; +const amount = 10; export const options = { thresholds: { @@ -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) {