Skip to content

Commit

Permalink
switch end to end tests to randomized substring (#22114)
Browse files Browse the repository at this point in the history
add in tests which are randomized to provide more testing for the issue
that created `https://github.com/microsoft/vscode-python/issues/22104`
  • Loading branch information
eleanorjboyd authored Oct 2, 2023
1 parent 4f82418 commit 590c12a
Showing 1 changed file with 18 additions and 13 deletions.
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

0 comments on commit 590c12a

Please sign in to comment.