Skip to content

fix(testitall): Update context too large endpoints #318

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
API_SERVER_PORT=4000

# The response size limit for WA extensions, in bytes; Used by the Context too large tests. Default is 102400 bytes (100 KB).
# The response size limit for WA extension calls, in bytes; Used by the Context too large tests. Default is 102400 bytes (100 KB).
RESPONSE_SIZE_LIMIT=102400

# The session size limit for WA stateful sessions, in bytes; Used by the Context almost too large tests. Default is 130000 bytes (127 KB).
SESSION_SIZE_LIMIT=130000

# [Authentication Credentials]
# Basic Authentication
AUTH_USERNAME=WA_USERNAME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { generateHighEntropyString } from '../utils.js';

const LONG_MESSAGE = `This is a long message intended to demonstrate streaming large messages in smaller chunks. Breaking down messages into smaller parts helps simulate real-time data transmission over a network. This technique is particularly useful for streaming large files or continuous data streams like logs, chat messages, or live updates. By sending small chunks, we ensure the data is processed and displayed incrementally, providing a smoother and more responsive user experience. Each chunk represents a portion of the entire message, and they are sent sequentially with a slight delay to mimic real-world streaming scenarios. This example uses a delay of 100 milliseconds between each chunk to achieve this effect.`;

// HTTP Methods
Expand Down Expand Up @@ -154,21 +156,17 @@ export function errorTest(req, res) {
});
}


export function contextTooLargeTest(req, res) {
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) * 5); // Default: 100KB * 5 = 650KB
export function responseTooLargeTest(req, res) {
const response = {
data: fakeData
data: generateHighEntropyString(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) * 5) // Default: 100KB * 5 = 650KB
}

return res.status(200).send(response);
}

export function contextAlmostTooLargeTest(req, res) {
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) - 1024); // Default: 100KB - 1KB = 99KB

const response = {
data: fakeData
data: generateHighEntropyString(parseInt(process.env.SESSION_SIZE_LIMIT, 10) / 2) // Default: 130KB / 2 = 65KB
}

return res.status(200).send(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ router.get('', testController.getTest);
router.put('', testController.putTest);
router.post('', testController.postTest);
router.patch('', testController.patchTest);

router.post('/error', testController.errorTest);
router.post('/params/:path_param', testController.postTest);
router.post('/auth_header', testController.authHeaderTest);

router.post('/arrays-root', testController.arraysRootTest);
router.post('/arrays-object', testController.arraysInObjectTest);
router.post('/context-too-large', testController.contextTooLargeTest);

router.post('/response-too-large', testController.responseTooLargeTest);
router.post('/context-too-large', testController.responseTooLargeTest); // for backwards compatibility

router.post('/context-almost-too-large', testController.contextAlmostTooLargeTest);

router.post('/non-json-response', testController.successfulPostWithNonJSONResponse);

router.post('/advanced/properties-counter', testController.propertiesByCounterTest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* High entropy string generator, used to generate the body of the response for the contextTooLargeTest and contextAlmostTooLargeTest endpoints
* to avoid being compressed by the server for more accurate testing results
* @param {number} length The length of the string to generate
* @returns {string} The generated string
*/
export function generateHighEntropyString(length) {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:",.<>?/~`'; // Large character set
let result = '';
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
Loading