2018-08-15 17:14:22 -07:00
|
|
|
// Flags: --expose-internals
|
2015-06-07 00:37:35 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2015-06-07 00:37:35 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
|
2018-08-15 17:14:22 -07:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
2018-12-19 14:14:57 -08:00
|
|
|
const StreamWrap = require('internal/js_stream_socket');
|
2018-08-15 17:14:22 -07:00
|
|
|
const { Duplex } = require('stream');
|
|
|
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
2015-06-07 00:37:35 +02:00
|
|
|
|
|
|
|
function testShutdown(callback) {
|
2017-01-08 13:19:00 +00:00
|
|
|
const stream = new Duplex({
|
2015-06-07 00:37:35 +02:00
|
|
|
read: function() {
|
|
|
|
},
|
|
|
|
write: function() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const wrap = new StreamWrap(stream);
|
2015-06-07 00:37:35 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = new ShutdownWrap();
|
2015-06-07 00:37:35 +02:00
|
|
|
req.oncomplete = function(code) {
|
|
|
|
assert(code < 0);
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
req.handle = wrap._handle;
|
|
|
|
|
|
|
|
// Close the handle to simulate
|
|
|
|
wrap.destroy();
|
|
|
|
req.handle.shutdown(req);
|
|
|
|
}
|
|
|
|
|
2017-03-24 09:46:44 -07:00
|
|
|
testShutdown(common.mustCall());
|