GeezerVison is showing github.com — [squash] cleanup tests · nodejs/node@b8f8f4b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.chain-promise-before-init-hooks.js +16-19Lines changed: 16 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,37 +5,34 @@ const assert = require('assert'); | 5 | 5 | const initHooks = require('./init-hooks'); | 6 | 6 | const { checkInvocations } = require('./hook-checks'); | 7 | 7 |
| 8 | | -const p = (new Promise(common.mustCall(executor))); | 9 | | -p.then(afterresolution); | | 8 | +const p = new Promise(common.mustCall(function executor(resolve, reject) { | | 9 | + resolve(5); | | 10 | +})); | | 11 | + | | 12 | +p.then(function afterresolution(val) { | | 13 | + assert.strictEqual(val, 5); | | 14 | + return val; | | 15 | +}); | 10 | 16 |
| 11 | 17 | // init hooks after chained promise is created | 12 | 18 | const hooks = initHooks(); | 13 | 19 | hooks._allowNoInit = true; | 14 | 20 | hooks.enable(); | 15 | 21 |
| 16 | | -function executor(resolve, reject) { | 17 | | - resolve(5); | 18 | | -} | 19 | | - | 20 | | -function afterresolution(val) { | 21 | | - assert.strictEqual(val, 5); | 22 | | - return val; | 23 | | -} | 24 | 22 |
| 25 | | -process.on('exit', onexit); | 26 | | -function onexit() { | | 23 | +process.on('exit', function onexit() { | 27 | 24 | hooks.disable(); | 28 | 25 | hooks.sanityCheck('PROMISE'); | 29 | 26 |
| | 27 | + // Because the init event was never emitted the hooks listener doesn't | | 28 | + // know what the type was. Thus check for Unknown rather than PROMISE. | 30 | 29 | const as = hooks.activitiesOfTypes('PROMISE'); | 31 | 30 | const unknown = hooks.activitiesOfTypes('Unknown'); | 32 | | - assert.strictEqual(as.length, 0, 'no activities with PROMISE type'); | 33 | | - assert.strictEqual(unknown.length, 1, | 34 | | - 'one activity with Unknown type which in fact is PROMISE'); | | 31 | + assert.strictEqual(as.length, 0); | | 32 | + assert.strictEqual(unknown.length, 1); | 35 | 33 |
| 36 | 34 | const a0 = unknown[0]; | 37 | | - assert.strictEqual(a0.type, 'Unknown', | 38 | | - 'unknown request which in fact is PROMISE'); | 39 | | - assert.strictEqual(typeof a0.uid, 'number', 'uid is a number'); | | 35 | + assert.strictEqual(a0.type, 'Unknown'); | | 36 | + assert.strictEqual(typeof a0.uid, 'number'); | 40 | 37 | checkInvocations(a0, { before: 1, after: 1 }, 'when process exits'); | 41 | | -} | | 38 | +}); |
Collapse file Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ p.then(afterresolution); | 14 | 14 |
| 15 | 15 | function executor(resolve, reject) { | 16 | 16 | const as = hooks.activitiesOfTypes('PROMISE'); | 17 | | - assert.strictEqual(as.length, 1, 'one activity'); | | 17 | + assert.strictEqual(as.length, 1, 'one activities'); | 18 | 18 | const a = as[0]; | 19 | 19 | checkInvocations(a, { init: 1 }, 'while in promise executor'); | 20 | 20 | resolve(5); | @@ -46,8 +46,7 @@ function onexit() { | 46 | 46 | const a1 = as[1]; | 47 | 47 | assert.strictEqual(a1.type, 'PROMISE', 'promise request'); | 48 | 48 | assert.strictEqual(typeof a1.uid, 'number', 'uid is a number'); | 49 | | - assert.strictEqual(a1.triggerId, a0.uid, | 50 | | - 'child promise should use parent uid as triggerId'); | | 49 | + assert.strictEqual(a1.triggerId, a0.uid); | 51 | 50 | // We expect a destroy hook as well but we cannot guarentee predictable gc. | 52 | 51 | checkInvocations(a1, { init: 1, before: 1, after: 1 }, 'when process exits'); | 53 | 52 | } |
Collapse file Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.promise-before-init-hooks.js +16-21Lines changed: 16 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,43 +5,38 @@ const assert = require('assert'); | 5 | 5 | const initHooks = require('./init-hooks'); | 6 | 6 | const { checkInvocations } = require('./hook-checks'); | 7 | 7 |
| 8 | | -const p = (new Promise(common.mustCall(executor))); | | 8 | +const p = new Promise(common.mustCall(function executor(resolve, reject) { | | 9 | + resolve(5); | | 10 | +})); | 9 | 11 |
| 10 | 12 | // init hooks after promise was created | 11 | | -const hooks = initHooks(); | 12 | | -hooks._allowNoInit = true; | | 13 | +const hooks = initHooks({allowNoInit: true}); | 13 | 14 | hooks.enable(); | 14 | 15 |
| 15 | | -p.then(afterresolution); | 16 | | - | 17 | | -function executor(resolve, reject) { | 18 | | - resolve(5); | 19 | | -} | 20 | | - | 21 | | -function afterresolution(val) { | | 16 | +p.then(function afterresolution(val) { | 22 | 17 | assert.strictEqual(val, 5); | 23 | 18 | const as = hooks.activitiesOfTypes('PROMISE'); | 24 | 19 | assert.strictEqual(as.length, 1, 'one activity'); | 25 | 20 | checkInvocations(as[0], { init: 1, before: 1 }, | 26 | 21 | 'after resolution child promise'); | 27 | 22 | return val; | 28 | | -} | | 23 | +}); | 29 | 24 |
| 30 | | -process.on('exit', onexit); | 31 | | -function onexit() { | | 25 | +process.on('exit', function onexit() { | 32 | 26 | hooks.disable(); | 33 | 27 | hooks.sanityCheck('PROMISE'); | 34 | 28 |
| 35 | 29 | const as = hooks.activitiesOfTypes('PROMISE'); | 36 | | - assert.strictEqual(as.length, 1, | 37 | | - 'should only get one activity(child promise)'); | | 30 | + assert.strictEqual(as.length, 1); | 38 | 31 |
| 39 | 32 | const a0 = as[0]; | 40 | | - assert.strictEqual(a0.type, 'PROMISE', 'promise request'); | 41 | | - assert.strictEqual(typeof a0.uid, 'number', 'uid is a number'); | 42 | | - // we can't get the triggerId dynamically, we have to use static number here | 43 | | - assert.strictEqual(a0.triggerId - (a0.uid - 3), 2, | 44 | | - 'child promise should use parent uid as triggerId'); | | 33 | + assert.strictEqual(a0.type, 'PROMISE'); | | 34 | + assert.strictEqual(typeof a0.uid, 'number'); | | 35 | + // we can't get the asyncId from the parent dynamically, since init was | | 36 | + // never called. However, it is known that the parent promise was created | | 37 | + // immediately before the child promise, thus there should only be one | | 38 | + // difference in id. | | 39 | + assert.strictEqual(a0.triggerId, a0.uid - 1); | 45 | 40 | // We expect a destroy hook as well but we cannot guarentee predictable gc. | 46 | 41 | checkInvocations(a0, { init: 1, before: 1, after: 1 }, 'when process exits'); | 47 | | -} | | 42 | +}); |
|