summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-wrap.js
blob: 5a8b75d4dc1f19470b59e63256a6f178e38e2fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
require('../common');
const assert = require('assert');

const StreamWrap = require('_stream_wrap');
const Duplex = require('stream').Duplex;
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;

var done = false;

function testShutdown(callback) {
  var stream = new Duplex({
    read: function() {
    },
    write: function() {
    }
  });

  var wrap = new StreamWrap(stream);

  var req = new ShutdownWrap();
  req.oncomplete = function(code) {
    assert(code < 0);
    callback();
  };
  req.handle = wrap._handle;

  // Close the handle to simulate
  wrap.destroy();
  req.handle.shutdown(req);
}

testShutdown(function() {
  done = true;
});

process.on('exit', function() {
  assert(done);
});