GeezerVison is showing github.com — test: fix flaky timeout-delayed-body and headers tests · nodejs/node@1cb3d89
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-request-timeout-delayed-body.js +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ const { connect } = require('net'); | 9 | 9 | // after server.requestTimeout if the client | 10 | 10 | // pauses before start sending the body. | 11 | 11 |
| | 12 | +let sendDelayedRequestBody; | 12 | 13 | const server = createServer(common.mustCall((req, res) => { | 13 | 14 | let body = ''; | 14 | 15 | req.setEncoding('utf-8'); | @@ -22,6 +23,9 @@ const server = createServer(common.mustCall((req, res) => { | 22 | 23 | res.write(body); | 23 | 24 | res.end(); | 24 | 25 | }); | | 26 | + | | 27 | + assert.strictEqual(typeof sendDelayedRequestBody, 'function'); | | 28 | + sendDelayedRequestBody(); | 25 | 29 | })); | 26 | 30 |
| 27 | 31 | // 0 seconds is the default | @@ -44,9 +48,11 @@ server.listen(0, common.mustCall(() => { | 44 | 48 | client.write('Connection: close\r\n'); | 45 | 49 | client.write('\r\n'); | 46 | 50 |
| 47 | | - setTimeout(() => { | 48 | | - client.write('12345678901234567890\r\n\r\n'); | 49 | | - }, common.platformTimeout(2000)).unref(); | | 51 | + sendDelayedRequestBody = common.mustCall(() => { | | 52 | + setTimeout(() => { | | 53 | + client.write('12345678901234567890\r\n\r\n'); | | 54 | + }, common.platformTimeout(2000)).unref(); | | 55 | + }); | 50 | 56 |
| 51 | 57 | const errOrEnd = common.mustCall(function(err) { | 52 | 58 | console.log(err); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-request-timeout-delayed-headers.js +13-8Lines changed: 13 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,9 +8,12 @@ const { connect } = require('net'); | 8 | 8 | // This test validates that the server returns 408 | 9 | 9 | // after server.requestTimeout if the client | 10 | 10 | // pauses before start sending the request. | 11 | | - | | 11 | +let sendDelayedRequestHeaders; | 12 | 12 | const server = createServer(common.mustNotCall()); | 13 | | - | | 13 | +server.on('connection', common.mustCall(() => { | | 14 | + assert.strictEqual(typeof sendDelayedRequestHeaders, 'function'); | | 15 | + sendDelayedRequestHeaders(); | | 16 | +})); | 14 | 17 | // 0 seconds is the default | 15 | 18 | assert.strictEqual(server.requestTimeout, 0); | 16 | 19 | const requestTimeout = common.platformTimeout(1000); | @@ -39,10 +42,12 @@ server.listen(0, common.mustCall(() => { | 39 | 42 |
| 40 | 43 | client.resume(); | 41 | 44 |
| 42 | | - setTimeout(() => { | 43 | | - client.write('POST / HTTP/1.1\r\n'); | 44 | | - client.write('Content-Length: 20\r\n'); | 45 | | - client.write('Connection: close\r\n\r\n'); | 46 | | - client.write('12345678901234567890\r\n\r\n'); | 47 | | - }, common.platformTimeout(2000)).unref(); | | 45 | + sendDelayedRequestHeaders = common.mustCall(() => { | | 46 | + setTimeout(() => { | | 47 | + client.write('POST / HTTP/1.1\r\n'); | | 48 | + client.write('Content-Length: 20\r\n'); | | 49 | + client.write('Connection: close\r\n\r\n'); | | 50 | + client.write('12345678901234567890\r\n\r\n'); | | 51 | + }, common.platformTimeout(2000)).unref(); | | 52 | + }); | 48 | 53 | })); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-request-timeout-interrupted-body.js +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,7 @@ const { connect } = require('net'); | 8 | 8 | // This test validates that the server returns 408 | 9 | 9 | // after server.requestTimeout if the client | 10 | 10 | // pauses sending in the middle of the body. | 11 | | - | | 11 | +let sendDelayedRequestBody; | 12 | 12 | const server = createServer(common.mustCall((req, res) => { | 13 | 13 | let body = ''; | 14 | 14 | req.setEncoding('utf-8'); | @@ -22,6 +22,9 @@ const server = createServer(common.mustCall((req, res) => { | 22 | 22 | res.write(body); | 23 | 23 | res.end(); | 24 | 24 | }); | | 25 | + | | 26 | + assert.strictEqual(typeof sendDelayedRequestBody, 'function'); | | 27 | + sendDelayedRequestBody(); | 25 | 28 | })); | 26 | 29 |
| 27 | 30 | // 0 seconds is the default | @@ -57,7 +60,9 @@ server.listen(0, common.mustCall(() => { | 57 | 60 | client.write('\r\n'); | 58 | 61 | client.write('1234567890'); | 59 | 62 |
| 60 | | - setTimeout(() => { | 61 | | - client.write('1234567890\r\n\r\n'); | 62 | | - }, common.platformTimeout(2000)).unref(); | | 63 | + sendDelayedRequestBody = common.mustCall(() => { | | 64 | + setTimeout(() => { | | 65 | + client.write('1234567890\r\n\r\n'); | | 66 | + }, common.platformTimeout(2000)).unref(); | | 67 | + }); | 63 | 68 | })); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-request-timeout-interrupted-headers.js +10-4Lines changed: 10 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,8 +8,12 @@ const { connect } = require('net'); | 8 | 8 | // This test validates that the server returns 408 | 9 | 9 | // after server.requestTimeout if the client | 10 | 10 | // pauses sending in the middle of a header. | 11 | | - | | 11 | +let sendDelayedRequestHeaders; | 12 | 12 | const server = createServer(common.mustNotCall()); | | 13 | +server.on('connection', common.mustCall(() => { | | 14 | + assert.strictEqual(typeof sendDelayedRequestHeaders, 'function'); | | 15 | + sendDelayedRequestHeaders(); | | 16 | +})); | 13 | 17 |
| 14 | 18 | // 120 seconds is the default | 15 | 19 | assert.strictEqual(server.requestTimeout, 0); | @@ -42,7 +46,9 @@ server.listen(0, common.mustCall(() => { | 42 | 46 | client.write('Connection: close\r\n'); | 43 | 47 | client.write('X-CRASH: '); | 44 | 48 |
| 45 | | - setTimeout(() => { | 46 | | - client.write('1234567890\r\n\r\n'); | 47 | | - }, common.platformTimeout(2000)).unref(); | | 49 | + sendDelayedRequestHeaders = common.mustCall(() => { | | 50 | + setTimeout(() => { | | 51 | + client.write('1234567890\r\n\r\n'); | | 52 | + }, common.platformTimeout(2000)).unref(); | | 53 | + }); | 48 | 54 | })); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-request-timeout-upgrade.js +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,8 +7,12 @@ const { connect } = require('net'); | 7 | 7 |
| 8 | 8 | // This test validates that the requestTimeoout | 9 | 9 | // is disabled after the connection is upgraded. | 10 | | - | | 10 | +let sendDelayedRequestHeaders; | 11 | 11 | const server = createServer(common.mustNotCall()); | | 12 | +server.on('connection', common.mustCall(() => { | | 13 | + assert.strictEqual(typeof sendDelayedRequestHeaders, 'function'); | | 14 | + sendDelayedRequestHeaders(); | | 15 | +})); | 12 | 16 |
| 13 | 17 | // 0 seconds is the default | 14 | 18 | assert.strictEqual(server.requestTimeout, 0); | @@ -48,8 +52,10 @@ server.listen(0, common.mustCall(() => { | 48 | 52 | client.write('Upgrade: WebSocket\r\n'); | 49 | 53 | client.write('Connection: Upgrade\r\n\r\n'); | 50 | 54 |
| 51 | | - setTimeout(() => { | 52 | | - client.write('12345678901234567890'); | 53 | | - client.end(); | 54 | | - }, common.platformTimeout(2000)).unref(); | | 55 | + sendDelayedRequestHeaders = common.mustCall(() => { | | 56 | + setTimeout(() => { | | 57 | + client.write('12345678901234567890'); | | 58 | + client.end(); | | 59 | + }, common.platformTimeout(2000)).unref(); | | 60 | + }); | 55 | 61 | })); |
|