-
Notifications
You must be signed in to change notification settings - Fork 30k
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
test: fix flaky http(s)-set-timeout-server tests #14380
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
845e15d
test: fix flaky http(s)-set-server-timeout tests
Trott 18086fd
squash: remove functions that might not be invoked
Trott eef98b1
squash: move timeout handler setting to end callback
Trott 7f7712e
squash: remove erroneous check that timeout is not emitted
Trott 5394374
squash: allow ECONNRESET in non-deterministic test
Trott b02787d
squash: whoops, missed a spot
Trott e3dc68f
squash: last of the flakiness, I think
Trott 340c06a
squash: comments per refack nits
Trott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,7 @@ function run() { | |
} | ||
|
||
test(function serverTimeout(cb) { | ||
const server = http.createServer((req, res) => { | ||
// Do nothing. We should get a timeout event. | ||
// Might not be invoked. Do not wrap in common.mustCall(). | ||
}); | ||
const server = http.createServer(); | ||
server.listen(common.mustCall(() => { | ||
const s = server.setTimeout(50, common.mustCall((socket) => { | ||
socket.destroy(); | ||
|
@@ -125,11 +122,14 @@ test(function serverResponseTimeoutWithPipeline(cb) { | |
const server = http.createServer((req, res) => { | ||
if (req.url === '/2') | ||
secReceived = true; | ||
if (req.url === '/1') { | ||
res.end(); | ||
return; | ||
} | ||
const s = res.setTimeout(50, () => { | ||
caughtTimeout += req.url; | ||
}); | ||
assert.ok(s instanceof http.OutgoingMessage); | ||
if (req.url === '/1') res.end(); | ||
}); | ||
server.on('timeout', common.mustCall((socket) => { | ||
if (secReceived) { | ||
|
@@ -152,17 +152,56 @@ test(function serverResponseTimeoutWithPipeline(cb) { | |
}); | ||
|
||
test(function idleTimeout(cb) { | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
req.on('timeout', common.mustNotCall()); | ||
res.on('timeout', common.mustNotCall()); | ||
res.end(); | ||
})); | ||
// Test that the an idle connection invokes the timeout callback. | ||
const server = http.createServer(); | ||
const s = server.setTimeout(50, common.mustCall((socket) => { | ||
socket.destroy(); | ||
server.close(); | ||
cb(); | ||
})); | ||
assert.ok(s instanceof http.Server); | ||
server.listen(common.mustCall(() => { | ||
const options = { | ||
port: server.address().port, | ||
allowHalfOpen: true, | ||
}; | ||
const c = net.connect(options, () => { | ||
// ECONNRESET could happen on a heavily-loaded server. | ||
c.on('error', (e) => { | ||
if (e.message !== 'read ECONNRESET') | ||
throw e; | ||
}); | ||
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); | ||
// Keep-Alive | ||
}); | ||
})); | ||
}); | ||
|
||
test(function fastTimeout(cb) { | ||
let connectionHandlerInvoked = false; | ||
let timeoutHandlerInvoked = false; | ||
let connectionSocket; | ||
|
||
function invokeCallbackIfDone() { | ||
if (connectionHandlerInvoked && timeoutHandlerInvoked) { | ||
connectionSocket.destroy(); | ||
server.close(); | ||
cb(); | ||
} | ||
} | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
req.on('timeout', common.mustNotCall()); | ||
res.end(); | ||
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. What happened to 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 might be emitted so |
||
connectionHandlerInvoked = true; | ||
invokeCallbackIfDone(); | ||
})); | ||
const s = server.setTimeout(1, common.mustCall((socket) => { | ||
connectionSocket = socket; | ||
timeoutHandlerInvoked = true; | ||
invokeCallbackIfDone(); | ||
})); | ||
assert.ok(s instanceof http.Server); | ||
server.listen(common.mustCall(() => { | ||
const options = { | ||
port: server.address().port, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Comment... (this one tests that timeout callback is fired for the socket but not for
req
)