diff --git a/k6/src/k6/send-messages.test.ts b/k6/src/k6/send-messages.test.ts index 44c5416..64f0f2f 100644 --- a/k6/src/k6/send-messages.test.ts +++ b/k6/src/k6/send-messages.test.ts @@ -4,7 +4,6 @@ import { Counter, Trend } from "k6/metrics"; import http, { RefinedParams, RefinedResponse, ResponseType } from "k6/http"; import { check, fail } from "k6"; import ws from "k6/ws"; -import crypto from 'k6/crypto'; // 1. Begin Init section const nodes = __ENV.NODES || "many2many"; @@ -18,7 +17,9 @@ const amountOfReceivers = nodesData.nodes.filter( node.enabled && node.isReceiver != undefined && node.isReceiver, ).length; -const MaxPayloadBytes = 325; +const MaxPayloadBytes = 400; +const Alphabet = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // Override API Token if (__ENV.HOPRD_API_TOKEN) { @@ -247,15 +248,17 @@ export function multipleHopMessage(dataPool: { ); } +// use random ASCI chars to extend the payload +// UTF-8 uses variying byte sizes - try to keep them in the single byte range +// so we have a predicatble payload size function extendWrandomBytes(body: string): string { const count = MaxPayloadBytes - body.length - 1; - const bytes = crypto.randomBytes(count); - const uintArray = new Uint8Array(bytes); - const str = uintArray.reduce((acc, v) => { - acc += String.fromCharCode(v); - return acc; - }, ""); - return `${body} ${str}`; + let rndmContent = ""; + for (let i = 0; i < count; i++) { + const idx = Math.floor(Math.random() * Alphabet.length); + rndmContent += Alphabet.charAt(idx); + } + return `${body} ${rndmContent}`; } export function teardown(dataPool: {