-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathasync_calls.test.js
42 lines (35 loc) · 983 Bytes
/
async_calls.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();
}
});
});