mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: fix flaky http-chunk-extensions-limit test
Replace the setInterval with a queueMicrotask to make test less flaky. Fixes: https://github.com/nodejs/node/issues/51883 PR-URL: https://github.com/nodejs/node/pull/51943 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
This commit is contained in:
@@ -5,6 +5,11 @@ const http = require('http');
|
||||
const net = require('net');
|
||||
const assert = require('assert');
|
||||
|
||||
// The maximum http chunk extension size is set in `src/node_http_parser.cc`.
|
||||
// These tests assert that once the extension size is reached, an HTTP 413
|
||||
// response is returned.
|
||||
// Currently, the max size is set to 16KiB (16384).
|
||||
|
||||
// Verify that chunk extensions are limited in size when sent all together.
|
||||
{
|
||||
const server = http.createServer((req, res) => {
|
||||
@@ -17,7 +22,8 @@ const assert = require('assert');
|
||||
});
|
||||
|
||||
server.listen(0, () => {
|
||||
const sock = net.connect(server.address().port);
|
||||
const port = server.address().port;
|
||||
const sock = net.connect(port);
|
||||
let data = '';
|
||||
|
||||
sock.on('data', (chunk) => data += chunk.toString('utf-8'));
|
||||
@@ -29,15 +35,17 @@ const assert = require('assert');
|
||||
|
||||
sock.end('' +
|
||||
'GET / HTTP/1.1\r\n' +
|
||||
'Host: localhost:8080\r\n' +
|
||||
`Host: localhost:${port}\r\n` +
|
||||
'Transfer-Encoding: chunked\r\n\r\n' +
|
||||
'2;' + 'A'.repeat(20000) + '=bar\r\nAA\r\n' +
|
||||
'0\r\n\r\n'
|
||||
'2;' + 'a'.repeat(17000) + '\r\n' + // Chunk size + chunk ext + CRLF
|
||||
'AA\r\n' + // Chunk data
|
||||
'0\r\n' + // Last chunk
|
||||
'\r\n' // End of http message
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Verify that chunk extensions are limited in size when sent in intervals.
|
||||
// Verify that chunk extensions are limited in size when sent in parts
|
||||
{
|
||||
const server = http.createServer((req, res) => {
|
||||
req.on('end', () => {
|
||||
@@ -49,24 +57,10 @@ const assert = require('assert');
|
||||
});
|
||||
|
||||
server.listen(0, () => {
|
||||
const sock = net.connect(server.address().port);
|
||||
let remaining = 20000;
|
||||
const port = server.address().port;
|
||||
const sock = net.connect(port);
|
||||
let data = '';
|
||||
|
||||
const interval = setInterval(
|
||||
() => {
|
||||
if (remaining > 0) {
|
||||
sock.write('A'.repeat(1000));
|
||||
} else {
|
||||
sock.write('=bar\r\nAA\r\n0\r\n\r\n');
|
||||
clearInterval(interval);
|
||||
}
|
||||
|
||||
remaining -= 1000;
|
||||
},
|
||||
common.platformTimeout(20),
|
||||
).unref();
|
||||
|
||||
sock.on('data', (chunk) => data += chunk.toString('utf-8'));
|
||||
|
||||
sock.on('end', common.mustCall(function() {
|
||||
@@ -76,10 +70,20 @@ const assert = require('assert');
|
||||
|
||||
sock.write('' +
|
||||
'GET / HTTP/1.1\r\n' +
|
||||
'Host: localhost:8080\r\n' +
|
||||
`Host: localhost:${port}\r\n` +
|
||||
'Transfer-Encoding: chunked\r\n\r\n' +
|
||||
'2;'
|
||||
'2;' // Chunk size + start of chunk-extension
|
||||
);
|
||||
|
||||
sock.write('A'.repeat(8500)); // Write half of the chunk-extension
|
||||
|
||||
queueMicrotask(() => {
|
||||
sock.write('A'.repeat(8500) + '\r\n' + // Remaining half of the chunk-extension
|
||||
'AA\r\n' + // Chunk data
|
||||
'0\r\n' + // Last chunk
|
||||
'\r\n' // End of http message
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,7 +99,8 @@ const assert = require('assert');
|
||||
});
|
||||
|
||||
server.listen(0, () => {
|
||||
const sock = net.connect(server.address().port);
|
||||
const port = server.address().port;
|
||||
const sock = net.connect(port);
|
||||
let data = '';
|
||||
|
||||
sock.on('data', (chunk) => data += chunk.toString('utf-8'));
|
||||
@@ -120,7 +125,7 @@ const assert = require('assert');
|
||||
|
||||
sock.end('' +
|
||||
'GET / HTTP/1.1\r\n' +
|
||||
'Host: localhost:8080\r\n' +
|
||||
`Host: localhost:${port}\r\n` +
|
||||
'Transfer-Encoding: chunked\r\n\r\n' +
|
||||
'2;' + 'A'.repeat(10000) + '=bar\r\nAA\r\n' +
|
||||
'2;' + 'A'.repeat(10000) + '=bar\r\nAA\r\n' +
|
||||
|
||||
Reference in New Issue
Block a user