aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-http-abort-stream-end.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-07-14 15:05:24 -0700
committerJames M Snell <jasnell@gmail.com>2017-07-24 14:16:49 -0700
commitb0a8a7c6baccea746da10e01bfb3dec18c0d723e (patch)
tree3bdf54ff6e3daa9c6ac9816914c7a51b892021dd /test/parallel/test-http-abort-stream-end.js
parented21cb1774d3e146f84a94400db0008a940656c3 (diff)
downloadandroid-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.tar.gz
android-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.tar.bz2
android-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.zip
test: improvements to various http tests
* Add common/countdown utility * Numerous improvements to http tests PR-URL: https://github.com/nodejs/node/pull/14315 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-http-abort-stream-end.js')
-rw-r--r--test/parallel/test-http-abort-stream-end.js25
1 files changed, 12 insertions, 13 deletions
diff --git a/test/parallel/test-http-abort-stream-end.js b/test/parallel/test-http-abort-stream-end.js
index ea14fe0ca9..8d2704a1ee 100644
--- a/test/parallel/test-http-abort-stream-end.js
+++ b/test/parallel/test-http-abort-stream-end.js
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
const http = require('http');
@@ -28,20 +28,21 @@ const http = require('http');
const maxSize = 1024;
let size = 0;
-const s = http.createServer(function(req, res) {
- this.close();
+const server = http.createServer(common.mustCall((req, res) => {
+ server.close();
res.writeHead(200, { 'Content-Type': 'text/plain' });
for (let i = 0; i < maxSize; i++) {
- res.write('x' + i);
+ res.write(`x${i}`);
}
res.end();
-});
+}));
let aborted = false;
-s.listen(0, function() {
- const req = http.get('http://localhost:' + s.address().port, function(res) {
- res.on('data', function(chunk) {
+server.listen(0, () => {
+
+ const res = common.mustCall((res) => {
+ res.on('data', (chunk) => {
size += chunk.length;
assert(!aborted, 'got data after abort');
if (size > maxSize) {
@@ -50,11 +51,9 @@ s.listen(0, function() {
size = maxSize;
}
});
+
+ req.on('abort', common.mustCall(() => assert.strictEqual(size, maxSize)));
});
-});
-process.on('exit', function() {
- assert(aborted);
- assert.strictEqual(size, maxSize);
- console.log('ok');
+ const req = http.get(`http://localhost:${server.address().port}`, res);
});