Skip to content

Commit

Permalink
test: test add and remove for lib/domain
Browse files Browse the repository at this point in the history
Testing some of the more specific cases of using domain.add and
domain.remove. For example, calling domain.add twice with same event
emmiter and actually removing an event emitter from the domain.

PR-URL: #24163
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
dodev authored and BridgeAR committed Nov 13, 2018
1 parent 1c8b4d7 commit 0a104ef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/parallel/test-domain-add-remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

require('../common');
const assert = require('assert');
const domain = require('domain');
const EventEmitter = require('events');

const d = new domain.Domain();
const e = new EventEmitter();
const e2 = new EventEmitter();

d.add(e);
assert.strictEqual(e.domain, d);

// Adding the same event to a domain should not change the member count
let previousMemberCount = d.members.length;
d.add(e);
assert.strictEqual(previousMemberCount, d.members.length);

d.add(e2);
assert.strictEqual(e2.domain, d);

previousMemberCount = d.members.length;
d.remove(e2);
assert.notStrictEqual(e2.domain, d);
assert.strictEqual(previousMemberCount - 1, d.members.length);

0 comments on commit 0a104ef

Please sign in to comment.