-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #10724 PR-URL: #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>
- Loading branch information
Showing
3 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
})); | ||
})); | ||
})); | ||
} |