Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
test: simplify the test cases in http timeouts mix#43470
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -4,6 +4,7 @@ const common = require('../common'); | ||||
| const assert = require('assert'); | ||||
| const { createServer } = require('http'); | ||||
| const { connect } = require('net'); | ||||
| const { promisify } = require('util'); | ||||
| // This test validates that request are correct checked for both requests and headers timeout in various situations. | ||||
| @@ -16,10 +17,13 @@ const responseTimeout = 'HTTP/1.1 408 Request Timeout\r\n'; | ||||
| const headersTimeout = common.platformTimeout(2000); | ||||
| const connectionsCheckingInterval = headersTimeout / 4; | ||||
| const requestTimeout = headersTimeout * 2; | ||||
| const threadSleepDelay = requestTimeout + headersTimeout; | ||||
| const delay = promisify(setTimeout); | ||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||
| const server = createServer({ | ||||
| headersTimeout, | ||||
| requestTimeout: headersTimeout * 2, | ||||
| requestTimeout, | ||||
| keepAliveTimeout: 0, | ||||
| connectionsCheckingInterval | ||||
| }, common.mustCall((req, res) => { | ||||
| @@ -32,7 +36,7 @@ const server = createServer({ | ||||
| }, 4)); | ||||
| assert.strictEqual(server.headersTimeout, headersTimeout); | ||||
| assert.strictEqual(server.requestTimeout, headersTimeout * 2); | ||||
| assert.strictEqual(server.requestTimeout, requestTimeout); | ||||
| let i = 0; | ||||
| function createClient(server) { | ||||
| @@ -58,74 +62,48 @@ function createClient(server) { | ||||
| return request; | ||||
| } | ||||
| server.listen(0, common.mustCall(() => { | ||||
| server.listen(0, common.mustCall(() => (async () => { | ||||
| // Create first and second request and set headers | ||||
| const request1 = createClient(server); | ||||
| let request2; | ||||
| let request3; | ||||
| let request4; | ||||
| let request5; | ||||
| // Send the first request and stop before the body | ||||
| const request2 = createClient(server); | ||||
| request1.client.write(requestBodyPart1); | ||||
| // After a little while send two new requests | ||||
| setTimeout(() => { | ||||
| request2 = createClient(server); | ||||
| request3 = createClient(server); | ||||
| // Send the second request, stop in the middle of the headers | ||||
| request2.client.write(requestBodyPart1); | ||||
| // Send the second request, stop in the middle of the headers | ||||
| request3.client.write(requestBodyPart1); | ||||
| }, headersTimeout * 0.2); | ||||
| // After another little while send the last two new requests | ||||
| setTimeout(() => { | ||||
| request4 = createClient(server); | ||||
| request5 = createClient(server); | ||||
| // Send the fourth request, stop in the middle of the headers | ||||
| request4.client.write(requestBodyPart1); | ||||
| // Send the fifth request, stop in the middle of the headers | ||||
| request5.client.write(requestBodyPart1); | ||||
| }, headersTimeout * 0.6); | ||||
| setTimeout(() => { | ||||
| // Finish the first request | ||||
| request1.client.write(requestBodyPart2 + requestBodyPart3); | ||||
| // Complete headers for all requests but second | ||||
| request3.client.write(requestBodyPart2); | ||||
| request4.client.write(requestBodyPart2); | ||||
| request5.client.write(requestBodyPart2); | ||||
| }, headersTimeout * 0.8); | ||||
| setTimeout(() => { | ||||
| // After the first timeout, the first request should have been completed and second timedout | ||||
| assert(request1.completed); | ||||
| assert(request2.completed); | ||||
| assert(!request3.completed); | ||||
| assert(!request4.completed); | ||||
| assert(!request5.completed); | ||||
| assert(request1.response.startsWith(responseOk)); | ||||
| assert(request2.response.startsWith(responseTimeout)); // It is expired due to headersTimeout | ||||
| }, headersTimeout * 1.2 + connectionsCheckingInterval); | ||||
| setTimeout(() => { | ||||
| // Complete the body for the fourth request | ||||
| request4.client.write(requestBodyPart3); | ||||
| }, headersTimeout * 1.5); | ||||
| setTimeout(() => { | ||||
| // All request should be completed now, either with 200 or 408 | ||||
| assert(request3.completed); | ||||
| assert(request4.completed); | ||||
| assert(request5.completed); | ||||
| assert(request3.response.startsWith(responseTimeout)); // It is expired due to requestTimeout | ||||
| assert(request4.response.startsWith(responseOk)); | ||||
| assert(request5.response.startsWith(responseTimeout)); // It is expired due to requestTimeout | ||||
| server.close(); | ||||
| }, headersTimeout * 3 + connectionsCheckingInterval); | ||||
| })); | ||||
| request2.client.write(requestBodyPart1); | ||||
| // Finish the first request now and wait more than the request timeout value | ||||
| request1.client.write(requestBodyPart2 + requestBodyPart3); | ||||
| await delay(threadSleepDelay); | ||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding this changes the original test. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not exactly Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's not like this in the original test. All request are created in a MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. But, basically we are testing 5 requests header timeout. In the previous pattern, we are doing it using some setTimeout functions and it was causing the flaky.
| ||||
| // First and second request should complete now | ||||
| assert(request1.completed); | ||||
| assert(request2.completed); // Completed, but a timeout request | ||||
| assert(request1.response.startsWith(responseOk)); | ||||
| assert(request2.response.startsWith(responseTimeout)); // Reques expired due to headersTimeout | ||||
| // Create another 3 requests with headers | ||||
| const request3 = createClient(server); | ||||
| const request4 = createClient(server); | ||||
| const request5 = createClient(server); | ||||
| request3.client.write(requestBodyPart1 + requestBodyPart2); | ||||
| request4.client.write(requestBodyPart1 + requestBodyPart2); | ||||
| request5.client.write(requestBodyPart1 + requestBodyPart2); | ||||
| // None of the requests will be completed because they only recieved headers | ||||
| assert(!request3.completed); | ||||
| assert(!request4.completed); | ||||
| assert(!request5.completed); | ||||
| // Finish the fourth request now and wait more than the request timeout value | ||||
| request4.client.write(requestBodyPart3); | ||||
| await delay(threadSleepDelay); | ||||
| // All three requests should complete now | ||||
| assert(request3.completed); | ||||
| assert(request4.completed); | ||||
| assert(request5.completed); | ||||
| assert(request3.response.startsWith(responseTimeout)); // It is expired due to headersTimeout | ||||
| assert(request4.response.startsWith(responseOk)); | ||||
| assert(request5.response.startsWith(responseTimeout)); // It is expired due to headersTimeout | ||||
| server.close(); | ||||
| })().then(common.mustCall()))); | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.