-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Converting test to use Countdown #17505
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
Changes from 7 commits
16e1c01
7c58d6d
b711964
c8c14ab
216cced
47d82f5
1f9a90d
a94c818
b97270a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,11 @@ | |
| // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| 'use strict'; | ||
| require('../common'); | ||
| -require('../common'); | ||
|
||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| const net = require('net'); | ||
| const Countdown = require('../common/countdown'); | ||
|
|
||
| const SERVER_RESPONSES = [ | ||
| 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n', | ||
|
|
@@ -41,34 +42,27 @@ const SHOULD_KEEP_ALIVE = [ | |
| true, // HTTP/1.1, Connection: keep-alive | ||
| false // HTTP/1.1, Connection: close | ||
| ]; | ||
| let requests = 0; | ||
| let responses = 0; | ||
| http.globalAgent.maxSockets = 5; | ||
|
|
||
| const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); | ||
|
||
|
|
||
| const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining | ||
|
||
|
|
||
| const server = net.createServer(function(socket) { | ||
| socket.write(SERVER_RESPONSES[requests]); | ||
| ++requests; | ||
| socket.write(SERVER_RESPONSES[getCountdownIndex()]); | ||
| }).listen(0, function() { | ||
| function makeRequest() { | ||
| const req = http.get({ port: server.address().port }, function(res) { | ||
| assert.strictEqual( | ||
| req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], | ||
| `${SERVER_RESPONSES[responses]} should ${ | ||
| SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`); | ||
| ++responses; | ||
| if (responses < SHOULD_KEEP_ALIVE.length) { | ||
| req.shouldKeepAlive, SHOULD_KEEP_ALIVE[getCountdownIndex()], | ||
| `${SERVER_RESPONSES[getCountdownIndex()]} should ${ | ||
| SHOULD_KEEP_ALIVE[getCountdownIndex()] ? '' : 'not '}Keep-Alive`); | ||
| countdown.dec(); | ||
| if (countdown.remaining) { | ||
| makeRequest(); | ||
| } else { | ||
| server.close(); | ||
| } | ||
| res.resume(); | ||
| }); | ||
| } | ||
|
|
||
| makeRequest(); | ||
| }); | ||
|
|
||
| process.on('exit', function() { | ||
| assert.strictEqual(requests, SERVER_RESPONSES.length); | ||
| assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length); | ||
| }); | ||
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.
I'm sorry, I should've been clearer. This is still required but it should not be assigned to a variable. Also, please try to run
make test -j4before committing as it will flag these types of issues in advance and also run the test being modified.