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

switch end to end tests to randomized substring #22114

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
31 changes: 18 additions & 13 deletions src/test/testing/testController/payloadTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ const SINGLE_PYTEST_PAYLOAD_TWO = {
},
};

function splitIntoRandomSubstrings(payload: string): string[] {
// split payload at random
const splitPayload = [];
const n = payload.length;
let remaining = n;
while (remaining > 0) {
// Randomly split what remains of the string
const randomSize = Math.floor(Math.random() * remaining) + 1;
splitPayload.push(payload.slice(n - remaining, n - remaining + randomSize));

remaining -= randomSize;
}
return splitPayload;
}

export function createPayload(uuid: string, data: unknown): string {
return `Content-Length: ${JSON.stringify(data).length}
Content-Type: application/json
Expand Down Expand Up @@ -104,13 +119,7 @@ export function PAYLOAD_ONLY_HEADER_MULTI_CHUNK(uuid: string): DataWithPayloadCh
// single payload divided by an arbitrary character and split across payloads
export function PAYLOAD_SPLIT_ACROSS_CHUNKS_ARRAY(uuid: string): DataWithPayloadChunks {
const payload = createPayload(uuid, SINGLE_PYTEST_PAYLOAD);
// payload length is know to be >200
const splitPayload: Array<string> = [
payload.substring(0, 50),
payload.substring(50, 100),
payload.substring(100, 150),
payload.substring(150),
];
const splitPayload = splitIntoRandomSubstrings(payload);
const finalResult = JSON.stringify(SINGLE_PYTEST_PAYLOAD.result);
splitPayload.push(EOT_PAYLOAD);
return {
Expand All @@ -121,12 +130,8 @@ export function PAYLOAD_SPLIT_ACROSS_CHUNKS_ARRAY(uuid: string): DataWithPayload

// here a payload is split across the buffer chunks and there are multiple payloads in a single buffer chunk
export function PAYLOAD_SPLIT_MULTI_CHUNK_ARRAY(uuid: string): DataWithPayloadChunks {
// payload1 length is know to be >200
const payload1 = createPayload(uuid, SINGLE_PYTEST_PAYLOAD);
const payload2 = createPayload(uuid, SINGLE_PYTEST_PAYLOAD_TWO);

// chunk 1 is 50 char of payload1, chunk 2 is 50-end of payload1 and all of payload2
const splitPayload: Array<string> = [payload1.substring(0, 100), payload1.substring(100).concat(payload2)];
const payload = createPayload(uuid, SINGLE_PYTEST_PAYLOAD).concat(createPayload(uuid, SINGLE_PYTEST_PAYLOAD_TWO));
const splitPayload = splitIntoRandomSubstrings(payload);
const finalResult = JSON.stringify(SINGLE_PYTEST_PAYLOAD.result).concat(
JSON.stringify(SINGLE_PYTEST_PAYLOAD_TWO.result),
);
Expand Down
Loading