-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diagnostics_channel: early-exit tracing channel trace methods
PR-URL: #51915 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
- Loading branch information
1 parent
53ff3e5
commit b94d119
Showing
12 changed files
with
250 additions
and
100 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
60 changes: 0 additions & 60 deletions
60
test/parallel/test-diagnostics-channel-tracing-channel-async.js
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
test/parallel/test-diagnostics-channel-tracing-channel-callback-early-exit.js
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,19 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const channel = dc.tracingChannel('test'); | ||
|
||
const handlers = { | ||
start: common.mustNotCall(), | ||
end: common.mustNotCall(), | ||
asyncStart: common.mustNotCall(), | ||
asyncEnd: common.mustNotCall(), | ||
error: common.mustNotCall() | ||
}; | ||
|
||
// While subscribe occurs _before_ the callback executes, | ||
// no async events should be published. | ||
channel.traceCallback(setImmediate, 0, {}, null, common.mustCall()); | ||
channel.subscribe(handlers); |
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
43 changes: 43 additions & 0 deletions
43
test/parallel/test-diagnostics-channel-tracing-channel-callback.js
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,43 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('diagnostics_channel'); | ||
const assert = require('assert'); | ||
|
||
const channel = dc.tracingChannel('test'); | ||
|
||
const expectedResult = { foo: 'bar' }; | ||
const input = { foo: 'bar' }; | ||
const thisArg = { baz: 'buz' }; | ||
|
||
function check(found) { | ||
assert.deepStrictEqual(found, input); | ||
} | ||
|
||
function checkAsync(found) { | ||
check(found); | ||
assert.strictEqual(found.error, undefined); | ||
assert.deepStrictEqual(found.result, expectedResult); | ||
} | ||
|
||
const handlers = { | ||
start: common.mustCall(check), | ||
end: common.mustCall(check), | ||
asyncStart: common.mustCall(checkAsync), | ||
asyncEnd: common.mustCall(checkAsync), | ||
error: common.mustNotCall() | ||
}; | ||
|
||
channel.subscribe(handlers); | ||
|
||
channel.traceCallback(function(cb, err, res) { | ||
assert.deepStrictEqual(this, thisArg); | ||
setImmediate(cb, err, res); | ||
}, 0, input, thisArg, common.mustCall((err, res) => { | ||
assert.strictEqual(err, null); | ||
assert.deepStrictEqual(res, expectedResult); | ||
}), null, expectedResult); | ||
|
||
assert.throws(() => { | ||
channel.traceCallback(common.mustNotCall(), 0, input, thisArg, 1, 2, 3); | ||
}, /"callback" argument must be of type function/); |
21 changes: 21 additions & 0 deletions
21
test/parallel/test-diagnostics-channel-tracing-channel-promise-early-exit.js
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,21 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const channel = dc.tracingChannel('test'); | ||
|
||
const handlers = { | ||
start: common.mustNotCall(), | ||
end: common.mustNotCall(), | ||
asyncStart: common.mustNotCall(), | ||
asyncEnd: common.mustNotCall(), | ||
error: common.mustNotCall() | ||
}; | ||
|
||
// While subscribe occurs _before_ the promise resolves, | ||
// no async events should be published. | ||
channel.tracePromise(() => { | ||
return new Promise(setImmediate); | ||
}, {}); | ||
channel.subscribe(handlers); |
38 changes: 38 additions & 0 deletions
38
test/parallel/test-diagnostics-channel-tracing-channel-promise-error.js
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,38 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('diagnostics_channel'); | ||
const assert = require('assert'); | ||
|
||
const channel = dc.tracingChannel('test'); | ||
|
||
const expectedError = new Error('test'); | ||
const input = { foo: 'bar' }; | ||
const thisArg = { baz: 'buz' }; | ||
|
||
function check(found) { | ||
assert.deepStrictEqual(found, input); | ||
} | ||
|
||
const handlers = { | ||
start: common.mustCall(check), | ||
end: common.mustCall(check), | ||
asyncStart: common.mustCall(check), | ||
asyncEnd: common.mustCall(check), | ||
error: common.mustCall((found) => { | ||
check(found); | ||
assert.deepStrictEqual(found.error, expectedError); | ||
}) | ||
}; | ||
|
||
channel.subscribe(handlers); | ||
|
||
channel.tracePromise(function(value) { | ||
assert.deepStrictEqual(this, thisArg); | ||
return Promise.reject(value); | ||
}, input, thisArg, expectedError).then( | ||
common.mustNotCall(), | ||
common.mustCall((value) => { | ||
assert.deepStrictEqual(value, expectedError); | ||
}) | ||
); |
Oops, something went wrong.