-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Chrome's Async Stack Tagging API
https://developer.chrome.com/blog/devtools-modern-web-debugging/#linked-stack-traces This enables the Chrome developer tools to link the stack traces of the original event scheduling and the eventual execution on the runloop. This is available in Chrome 106 and above. To protect production performance, this is disabled-by-default, but can be enabled by setting `Backburner.ASYNC_STACKS = true`. Applications/frameworks could choose to enable this by default in development modes.
- Loading branch information
1 parent
af77b18
commit ea1882f
Showing
7 changed files
with
151 additions
and
22 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
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,75 @@ | ||
import Backburner from 'backburner'; | ||
|
||
const skipIfNotSupported = !!console["createTask"] ? QUnit.test : QUnit.skip; | ||
|
||
QUnit.module('tests/async_stacks'); | ||
|
||
QUnit.test("schedule - does not affect normal behaviour", function(assert) { | ||
let bb = new Backburner(['one']); | ||
let callCount = 0; | ||
|
||
bb.run(() => { | ||
bb.schedule("one", () => callCount += 1) | ||
bb.schedule("one", () => callCount += 1) | ||
}); | ||
assert.strictEqual(callCount, 2, "schedule works correctly with ASYNC_STACKS disabled"); | ||
|
||
bb.ASYNC_STACKS = true; | ||
|
||
bb.run(() => { | ||
bb.schedule("one", () => callCount += 1) | ||
bb.schedule("one", () => callCount += 1) | ||
}); | ||
assert.strictEqual(callCount, 4, "schedule works correctly with ASYNC_STACKS enabled"); | ||
}); | ||
|
||
skipIfNotSupported('schedule - ASYNC_STACKS flag enables async stack tagging', function(assert) { | ||
let bb = new Backburner(['one']); | ||
|
||
bb.schedule('one', () => {}); | ||
|
||
assert.true(bb.currentInstance && (bb.currentInstance.queues.one.consoleTaskFor(0) === undefined), 'No consoleTask is stored'); | ||
|
||
bb.ASYNC_STACKS = true; | ||
|
||
bb.schedule('one', () => {}); | ||
|
||
const task = bb.currentInstance && bb.currentInstance.queues.one.consoleTaskFor(1); | ||
assert.true(!!task?.run, 'consoleTask is stored in queue'); | ||
}); | ||
|
||
QUnit.test("later - ASYNC_STACKS does not affect normal behaviour", function(assert) { | ||
let bb = new Backburner(['one']); | ||
let done = assert.async(); | ||
bb.ASYNC_STACKS = true; | ||
|
||
bb.later(() => { | ||
assert.true(true, "timer called") | ||
done() | ||
}); | ||
}); | ||
|
||
|
||
skipIfNotSupported('later - skips async stack when ASYNC_STACKS is false', function(assert) { | ||
let done = assert.async(); | ||
let bb = new Backburner(['one']); | ||
|
||
bb.later(() => { | ||
const task = bb.currentInstance && bb.currentInstance.queues.one.consoleTaskFor(0, true); | ||
assert.true(bb.currentInstance && (bb.currentInstance.queues.one.consoleTaskFor(0, true) === undefined), 'consoleTask is not stored') | ||
done(); | ||
}); | ||
}); | ||
|
||
|
||
skipIfNotSupported('later - ASYNC_STACKS flag enables async stack tagging', function(assert) { | ||
let done = assert.async(); | ||
let bb = new Backburner(['one']); | ||
bb.ASYNC_STACKS = true; | ||
|
||
bb.later(() => { | ||
const task = bb.currentInstance && bb.currentInstance.queues.one.consoleTaskFor(0, true); | ||
assert.true(!!task?.run, 'consoleTask is stored in timer queue and then passed to runloop queue') | ||
done(); | ||
}); | ||
}); |
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