2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2020-02-16 10:47:13 +01:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2013-08-15 11:08:19 -07:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const http = require('http');
|
2013-08-15 11:08:19 -07:00
|
|
|
|
|
|
|
http.createServer(function(req, res) {
|
|
|
|
req.resume();
|
2014-01-24 07:03:10 -08:00
|
|
|
req.on('end', function() {
|
|
|
|
write(res);
|
|
|
|
});
|
2013-08-15 11:08:19 -07:00
|
|
|
this.close();
|
2016-05-29 03:06:56 -04:00
|
|
|
}).listen(0, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = http.request({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2013-08-15 11:08:19 -07:00
|
|
|
method: 'PUT'
|
|
|
|
});
|
|
|
|
write(req);
|
|
|
|
req.on('response', function(res) {
|
|
|
|
res.resume();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const buf = Buffer.alloc(1024 * 16, 'x');
|
2013-08-15 11:08:19 -07:00
|
|
|
function write(out) {
|
2017-01-08 13:19:00 +00:00
|
|
|
const name = out.constructor.name;
|
|
|
|
let finishEvent = false;
|
|
|
|
let endCb = false;
|
2013-08-15 11:08:19 -07:00
|
|
|
|
2019-01-21 01:22:27 +01:00
|
|
|
// First, write until it gets some backpressure
|
2022-02-02 22:35:32 -08:00
|
|
|
while (out.write(buf, common.mustSucceed()));
|
2013-08-15 11:08:19 -07:00
|
|
|
|
2018-12-10 13:27:32 +01:00
|
|
|
// Now end, and make sure that we don't get the 'finish' event
|
2013-08-15 11:08:19 -07:00
|
|
|
// before the tick where the cb gets called. We give it until
|
|
|
|
// nextTick because this is added as a listener before the endcb
|
|
|
|
// is registered. The order is not what we're testing here, just
|
|
|
|
// that 'finish' isn't emitted until the stream is fully flushed.
|
|
|
|
out.on('finish', function() {
|
|
|
|
finishEvent = true;
|
2018-01-10 15:05:15 +05:30
|
|
|
console.error(`${name} finish event`);
|
2013-08-15 11:08:19 -07:00
|
|
|
process.nextTick(function() {
|
2017-04-28 04:06:42 +03:00
|
|
|
assert(endCb, `${name} got finish event before endcb!`);
|
2018-01-10 15:05:15 +05:30
|
|
|
console.log(`ok - ${name} finishEvent`);
|
2013-08-15 11:08:19 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-16 10:47:13 +01:00
|
|
|
out.end(buf, common.mustCall(function() {
|
2013-08-15 11:08:19 -07:00
|
|
|
endCb = true;
|
2018-01-10 15:05:15 +05:30
|
|
|
console.error(`${name} endCb`);
|
2013-08-15 11:08:19 -07:00
|
|
|
process.nextTick(function() {
|
2017-04-28 04:06:42 +03:00
|
|
|
assert(finishEvent, `${name} got endCb event before finishEvent!`);
|
2018-01-10 15:05:15 +05:30
|
|
|
console.log(`ok - ${name} endCb`);
|
2013-08-15 11:08:19 -07:00
|
|
|
});
|
2020-02-16 10:47:13 +01:00
|
|
|
}));
|
2013-08-15 11:08:19 -07:00
|
|
|
}
|