-
-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed propagation of async hook IDs through callbacks (#1511)
- Loading branch information
1 parent
efee5f0
commit 4d31c19
Showing
2 changed files
with
43 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict" | ||
|
||
var sqlite3 = require('..'); | ||
const assert = require("assert"); | ||
const { createHook, executionAsyncId } = require("async_hooks"); | ||
|
||
|
||
describe('async_hooks', function() { | ||
let db; | ||
let dbId; | ||
let asyncHook; | ||
|
||
beforeEach(function() { | ||
db = new sqlite3.Database(':memory:'); | ||
|
||
asyncHook = createHook({ | ||
init(asyncId, type) { | ||
if (dbId == null && type.startsWith("sqlite3.")) { | ||
dbId = asyncId; | ||
} | ||
} | ||
}).enable(); | ||
}); | ||
|
||
it('should support performance measuring with async hooks', function(done) { | ||
db.run("DROP TABLE user", () => { | ||
const cbId = executionAsyncId(); | ||
assert.strictEqual(cbId, dbId); | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
if (asyncHook != null) { | ||
asyncHook.disable(); | ||
} | ||
dbId = null; | ||
if (db != null) { | ||
db.close(); | ||
} | ||
}); | ||
}); |