forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol-store-db.test.js
93 lines (77 loc) · 3.37 KB
/
symbol-store-db.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import SymbolStoreDB from '../../profile-logic/symbol-store-db';
import { completeSymbolTableAsTuple } from '../fixtures/example-symbol-table';
import { indexedDB, IDBKeyRange } from 'fake-indexeddb';
describe('SymbolStoreDB', function () {
const libs = Array.from({ length: 10 }).map((_, i) => ({
debugName: `firefox${i}`,
breakpadId: `breakpadId${i}`,
}));
beforeAll(function () {
// The SymbolStore requires IndexedDB, otherwise symbolication will be skipped.
window.indexedDB = indexedDB;
window.IDBKeyRange = IDBKeyRange;
});
afterAll(function () {
delete window.indexedDB;
delete window.IDBKeyRange;
});
it('should respect the maximum number of tables limit', async function () {
const symbolStoreDB = new SymbolStoreDB('testing-symbol-tables', 5); // maximum 5
// Try to store 10 symbol tables in a database that only allows 5.
// All stores should succeed but the first 5 should be evicted again.
for (const lib of libs) {
await symbolStoreDB.storeSymbolTable(
lib.debugName,
lib.breakpadId,
completeSymbolTableAsTuple
);
}
for (let i = 0; i < 5; i++) {
await expect(
symbolStoreDB.getSymbolTable(libs[i].debugName, libs[i].breakpadId)
).rejects.toBeInstanceOf(Error);
// .rejects.toMatch('does not exist in the database'); // TODO Some future verison of jest should make this work
}
for (let i = 5; i < 10; i++) {
// We should be able to retrieve all last 5 tables
await expect(
symbolStoreDB.getSymbolTable(libs[i].debugName, libs[i].breakpadId)
).resolves.toBeInstanceOf(Array);
}
await symbolStoreDB.close();
});
it('should still contain those five symbol tables after opening the database a second time', async function () {
const symbolStoreDB = new SymbolStoreDB('testing-symbol-tables', 5); // maximum 5
for (let i = 0; i < 5; i++) {
await expect(
symbolStoreDB.getSymbolTable(libs[i].debugName, libs[i].breakpadId)
).rejects.toBeInstanceOf(Error);
// .rejects.toMatch('does not exist in the database'); // TODO Some future verison of jest should make this work
}
for (let i = 5; i < 10; i++) {
// We should be able to retrieve all last 5 tables
await expect(
symbolStoreDB.getSymbolTable(libs[i].debugName, libs[i].breakpadId)
).resolves.toBeInstanceOf(Array);
}
await symbolStoreDB.close();
});
it('should still evict all tables when opening with the age limit set to 0ms', async function () {
// maximum count 10, maximum age -1
// Note we use -1 to force an eviction. With 0 in some platforms (cough cough
// Windows) we don't get an eviction because Date.now() isn't updated often
// enough.
const symbolStoreDB = new SymbolStoreDB('testing-symbol-tables', 10, -1);
for (let i = 0; i < 10; i++) {
await expect(
symbolStoreDB.getSymbolTable(libs[i].debugName, libs[i].breakpadId)
).rejects.toBeInstanceOf(Error);
// .rejects.toMatch('does not exist in the database'); // TODO Some future verison of jest should make this work
}
await symbolStoreDB.close();
});
});