diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-04-18 18:02:27 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-04-27 17:40:11 +0200 |
commit | 84dabe8373794d6df692b995fe64623e90eff1f7 (patch) | |
tree | 2fe17bbdb6b1673c6c6dda2973575f5b8098681b /test/parallel/test-domain-promise.js | |
parent | e5a25cbc8524f0d57c66de85eeb4b1b4eacd6da8 (diff) | |
download | android-node-v8-84dabe8373794d6df692b995fe64623e90eff1f7.tar.gz android-node-v8-84dabe8373794d6df692b995fe64623e90eff1f7.tar.bz2 android-node-v8-84dabe8373794d6df692b995fe64623e90eff1f7.zip |
domain: support promises
Fixes: https://github.com/nodejs/node/issues/10724
PR-URL: https://github.com/nodejs/node/pull/12489
Reviewed-By: Matthew Loring <mattloring@google.com>
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-domain-promise.js')
-rw-r--r-- | test/parallel/test-domain-promise.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/test/parallel/test-domain-promise.js b/test/parallel/test-domain-promise.js new file mode 100644 index 0000000000..8bae75eb63 --- /dev/null +++ b/test/parallel/test-domain-promise.js @@ -0,0 +1,128 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const domain = require('domain'); +const fs = require('fs'); +const vm = require('vm'); + +common.crashOnUnhandledRejection(); + +{ + const d = domain.create(); + + d.run(common.mustCall(() => { + Promise.resolve().then(common.mustCall(() => { + assert.strictEqual(process.domain, d); + })); + })); +} + +{ + const d = domain.create(); + + d.run(common.mustCall(() => { + Promise.resolve().then(() => {}).then(() => {}).then(common.mustCall(() => { + assert.strictEqual(process.domain, d); + })); + })); +} + +{ + const d = domain.create(); + + d.run(common.mustCall(() => { + vm.runInNewContext(`Promise.resolve().then(common.mustCall(() => { + assert.strictEqual(process.domain, d); + }));`, { common, assert, process, d }); + })); +} + +{ + const d1 = domain.create(); + const d2 = domain.create(); + let p; + d1.run(common.mustCall(() => { + p = Promise.resolve(42); + })); + + d2.run(common.mustCall(() => { + p.then(common.mustCall((v) => { + assert.strictEqual(process.domain, d2); + assert.strictEqual(p.domain, d1); + })); + })); +} + +{ + const d1 = domain.create(); + const d2 = domain.create(); + let p; + d1.run(common.mustCall(() => { + p = Promise.resolve(42); + })); + + d2.run(common.mustCall(() => { + p.then(p.domain.bind(common.mustCall((v) => { + assert.strictEqual(process.domain, d1); + assert.strictEqual(p.domain, d1); + }))); + })); +} + +{ + const d1 = domain.create(); + const d2 = domain.create(); + let p; + d1.run(common.mustCall(() => { + p = Promise.resolve(42); + })); + + d1.run(common.mustCall(() => { + d2.run(common.mustCall(() => { + p.then(common.mustCall((v) => { + assert.strictEqual(process.domain, d2); + assert.strictEqual(p.domain, d1); + })); + })); + })); +} + +{ + const d1 = domain.create(); + const d2 = domain.create(); + let p; + d1.run(common.mustCall(() => { + p = Promise.reject(new Error('foobar')); + })); + + d2.run(common.mustCall(() => { + p.catch(common.mustCall((v) => { + assert.strictEqual(process.domain, d2); + assert.strictEqual(p.domain, d1); + })); + })); +} + +{ + const d = domain.create(); + + d.run(common.mustCall(() => { + Promise.resolve().then(common.mustCall(() => { + setTimeout(common.mustCall(() => { + assert.strictEqual(process.domain, d); + }), 0); + })); + })); +} + +{ + const d = domain.create(); + + d.run(common.mustCall(() => { + Promise.resolve().then(common.mustCall(() => { + fs.readFile(__filename, common.mustCall(() => { + assert.strictEqual(process.domain, d); + })); + })); + })); +} |