summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 13:09:18 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 13:10:30 -0500
commit7b1a1480dc440eb1c7b1a6170ac0964bc4c7a3fa (patch)
treea6e210880c5b3cf600ca7819ad533f81be574bb7 /test
parenta54f44122a3a245c1b1579c15b2faf9d50c15c55 (diff)
Add a timeout to clearDatabase
This will trigger in case something goes wrong and a database isn't closed.
Diffstat (limited to 'test')
-rw-r--r--test/test-database.js45
1 files changed, 31 insertions, 14 deletions
diff --git a/test/test-database.js b/test/test-database.js
index 216ae5dd..6fe515e6 100644
--- a/test/test-database.js
+++ b/test/test-database.js
@@ -107,15 +107,25 @@ function countKanjiWithCharacter(kanji, character) {
}
-async function clearDatabase() {
- const indexedDB = global.indexedDB;
- for (const {name} of await indexedDB.databases()) {
- await new Promise((resolve, reject) => {
- const request = indexedDB.deleteDatabase(name);
- request.onerror = (e) => reject(e);
- request.onsuccess = () => resolve();
- });
- }
+function clearDatabase(timeout) {
+ return new Promise((resolve, reject) => {
+ const timer = setTimeout(() => {
+ reject(new Error(`clearDatabase failed to resolve after ${timeout}ms`));
+ }, timeout);
+
+ (async () => {
+ const indexedDB = global.indexedDB;
+ for (const {name} of await indexedDB.databases()) {
+ await new Promise((resolve, reject) => {
+ const request = indexedDB.deleteDatabase(name);
+ request.onerror = (e) => reject(e);
+ request.onsuccess = () => resolve();
+ });
+ }
+ clearTimeout(timer);
+ resolve();
+ })();
+ });
}
@@ -840,11 +850,18 @@ async function testDatabase2() {
async function main() {
- await testDatabase1();
- await clearDatabase();
-
- await testDatabase2();
- await clearDatabase();
+ const clearTimeout = 5000;
+ try {
+ await testDatabase1();
+ await clearDatabase(clearTimeout);
+
+ await testDatabase2();
+ await clearDatabase(clearTimeout);
+ } catch (e) {
+ console.log(e);
+ process.exit(-1);
+ throw e;
+ }
}