From 9970d562c65af98fee5bae28a5f956ed6238187c Mon Sep 17 00:00:00 2001 From: Petar Dodev Date: Tue, 6 Nov 2018 18:36:17 +0300 Subject: [PATCH] test: test add and remove for lib/domain 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: https://github.com/nodejs/node/pull/24163 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- test/parallel/test-domain-add-remove.js | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/parallel/test-domain-add-remove.js diff --git a/test/parallel/test-domain-add-remove.js b/test/parallel/test-domain-add-remove.js new file mode 100644 index 00000000000000..8e1d082125cb0b --- /dev/null +++ b/test/parallel/test-domain-add-remove.js @@ -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);