| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent da62c5c commit 0e6f720
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const async_hooks = require('async_hooks'); | ||
| 6 | + const binding = require(`./build/${common.buildType}/binding`); | ||
| 7 | + const makeCallback = binding.makeCallback; | ||
| 8 | + | ||
| 9 | + // Check async hooks integration using async context. | ||
| 10 | + const hook_result = { | ||
| 11 | + id: null, | ||
| 12 | + init_called: false, | ||
| 13 | + before_called: false, | ||
| 14 | + after_called: false, | ||
| 15 | + destroy_called: false, | ||
| 16 | + }; | ||
| 17 | + const test_hook = async_hooks.createHook({ | ||
| 18 | + init: (id, type) => { | ||
| 19 | + if (type === 'test') { | ||
| 20 | + hook_result.id = id; | ||
| 21 | + hook_result.init_called = true; | ||
| 22 | + } | ||
| 23 | + }, | ||
| 24 | + before: (id) => { | ||
| 25 | + if (id === hook_result.id) hook_result.before_called = true; | ||
| 26 | + }, | ||
| 27 | + after: (id) => { | ||
| 28 | + if (id === hook_result.id) hook_result.after_called = true; | ||
| 29 | + }, | ||
| 30 | + destroy: (id) => { | ||
| 31 | + if (id === hook_result.id) hook_result.destroy_called = true; | ||
| 32 | + }, | ||
| 33 | + }); | ||
| 34 | + | ||
| 35 | + test_hook.enable(); | ||
| 36 | + makeCallback(process, function() {}); | ||
| 37 | + | ||
| 38 | + assert.strictEqual(hook_result.init_called, true); | ||
| 39 | + assert.strictEqual(hook_result.before_called, true); | ||
| 40 | + assert.strictEqual(hook_result.after_called, true); | ||
| 41 | + setImmediate(() => { | ||
| 42 | + assert.strictEqual(hook_result.destroy_called, true); | ||
| 43 | + test_hook.disable(); | ||
| 44 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const common = require('../../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | - const async_hooks = require('async_hooks'); | ||
| 6 | 5 | const vm = require('vm'); | |
| 7 | 6 | const binding = require(`./build/${common.buildType}/binding`); | |
| 8 | 7 | const makeCallback = binding.makeCallback; | |
@@ -81,40 +80,3 @@ function endpoint($Object) { | |||
| 81 | 80 | } | |
| 82 | 81 | ||
| 83 | 82 | assert.strictEqual(Object, makeCallback(process, forward, endpoint)); | |
| 84 | - | ||
| 85 | - // Check async hooks integration using async context. | ||
| 86 | - const hook_result = { | ||
| 87 | - id: null, | ||
| 88 | - init_called: false, | ||
| 89 | - before_called: false, | ||
| 90 | - after_called: false, | ||
| 91 | - destroy_called: false, | ||
| 92 | - }; | ||
| 93 | - const test_hook = async_hooks.createHook({ | ||
| 94 | - init: (id, type) => { | ||
| 95 | - if (type === 'test') { | ||
| 96 | - hook_result.id = id; | ||
| 97 | - hook_result.init_called = true; | ||
| 98 | - } | ||
| 99 | - }, | ||
| 100 | - before: (id) => { | ||
| 101 | - if (id === hook_result.id) hook_result.before_called = true; | ||
| 102 | - }, | ||
| 103 | - after: (id) => { | ||
| 104 | - if (id === hook_result.id) hook_result.after_called = true; | ||
| 105 | - }, | ||
| 106 | - destroy: (id) => { | ||
| 107 | - if (id === hook_result.id) hook_result.destroy_called = true; | ||
| 108 | - }, | ||
| 109 | - }); | ||
| 110 | - | ||
| 111 | - test_hook.enable(); | ||
| 112 | - makeCallback(process, function() {}); | ||
| 113 | - | ||
| 114 | - assert.strictEqual(hook_result.init_called, true); | ||
| 115 | - assert.strictEqual(hook_result.before_called, true); | ||
| 116 | - assert.strictEqual(hook_result.after_called, true); | ||
| 117 | - setImmediate(() => { | ||
| 118 | - assert.strictEqual(hook_result.destroy_called, true); | ||
| 119 | - test_hook.disable(); | ||
| 120 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments