|
1 | 1 | 'use strict';
|
2 |
| -require('../common'); |
3 |
| -var http = require('http'); |
4 |
| -var assert = require('assert'); |
| 2 | +const common = require('../common'); |
| 3 | +const http = require('http'); |
| 4 | +const assert = require('assert'); |
5 | 5 |
|
6 | 6 | // first 204 or 304 works, subsequent anything fails
|
7 |
| -var codes = [204, 200]; |
| 7 | +const codes = [204, 200]; |
8 | 8 |
|
9 | 9 | // Methods don't really matter, but we put in something realistic.
|
10 |
| -var methods = ['DELETE', 'DELETE']; |
| 10 | +const methods = ['DELETE', 'DELETE']; |
11 | 11 |
|
12 |
| -var server = http.createServer(function(req, res) { |
13 |
| - var code = codes.shift(); |
14 |
| - assert.equal('number', typeof code); |
| 12 | +const server = http.createServer(common.mustCall((req, res) => { |
| 13 | + const code = codes.shift(); |
| 14 | + assert.strictEqual(typeof code, 'number'); |
15 | 15 | assert.ok(code > 0);
|
16 |
| - console.error('writing %d response', code); |
17 | 16 | res.writeHead(code, {});
|
18 | 17 | res.end();
|
19 |
| -}); |
| 18 | +}, codes.length)); |
20 | 19 |
|
21 | 20 | function nextRequest() {
|
22 |
| - var method = methods.shift(); |
23 |
| - console.error('writing request: %s', method); |
| 21 | + const method = methods.shift(); |
24 | 22 |
|
25 |
| - var request = http.request({ |
| 23 | + const request = http.request({ |
26 | 24 | port: server.address().port,
|
27 | 25 | method: method,
|
28 | 26 | path: '/'
|
29 |
| - }, function(response) { |
30 |
| - response.on('end', function() { |
| 27 | + }, common.mustCall((response) => { |
| 28 | + response.on('end', common.mustCall(() => { |
31 | 29 | if (methods.length === 0) {
|
32 |
| - console.error('close server'); |
33 | 30 | server.close();
|
34 | 31 | } else {
|
35 | 32 | // throws error:
|
36 | 33 | nextRequest();
|
37 | 34 | // works just fine:
|
38 | 35 | //process.nextTick(nextRequest);
|
39 | 36 | }
|
40 |
| - }); |
| 37 | + })); |
41 | 38 | response.resume();
|
42 |
| - }); |
| 39 | + })); |
43 | 40 | request.end();
|
44 | 41 | }
|
45 | 42 |
|
|
0 commit comments