summaryrefslogtreecommitdiff
path: root/test/parallel/test-async-wrap-disabled-propagate-parent.js
blob: 4a6df7500956bfa9a57ba6362c3a3450146b88c4 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';

require('../common');
const assert = require('assert');
const net = require('net');
const async_wrap = process.binding('async_wrap');
const providers = Object.keys(async_wrap.Providers);

const uidSymbol = Symbol('uid');

let cntr = 0;
let client;

function init(uid, type, parentUid, parentHandle) {
  this[uidSymbol] = uid;

  if (parentHandle) {
    cntr++;
    // Cannot assert in init callback or will abort.
    process.nextTick(() => {
      assert.strictEqual(providers[type], 'TCPWRAP');
      assert.strictEqual(parentUid, server._handle[uidSymbol],
                         'server uid doesn\'t match parent uid');
      assert.strictEqual(parentHandle, server._handle,
                         'server handle doesn\'t match parent handle');
      assert.strictEqual(this, client._handle, 'client doesn\'t match context');
    });
  }
}

function noop() { }

async_wrap.setupHooks({ init });
async_wrap.enable();

const server = net.createServer(function(c) {
  client = c;
  // Allow init callback to run before closing.
  setImmediate(() => {
    c.end();
    this.close();
  });
}).listen(0, function() {
  net.connect(this.address().port, noop);
});

async_wrap.disable();

process.on('exit', function() {
  // init should have only been called once with a parent.
  assert.strictEqual(cntr, 1);
});