gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: idb: fix test


From: gnunet
Subject: [taler-wallet-core] branch master updated: idb: fix test
Date: Mon, 22 Feb 2021 21:03:12 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 9b9df089 idb: fix test
9b9df089 is described below

commit 9b9df089cfddb2f01b17ac0eaccd2192a6982fb9
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Feb 22 21:03:06 2021 +0100

    idb: fix test
---
 packages/idb-bridge/src/bridge-idb.ts              |   9 +-
 .../src/idb-wpt-ported/cursor-overloads.test.ts    | 131 +++++++++++----------
 2 files changed, 75 insertions(+), 65 deletions(-)

diff --git a/packages/idb-bridge/src/bridge-idb.ts 
b/packages/idb-bridge/src/bridge-idb.ts
index 02fca9d1..836f2efa 100644
--- a/packages/idb-bridge/src/bridge-idb.ts
+++ b/packages/idb-bridge/src/bridge-idb.ts
@@ -936,10 +936,6 @@ export class BridgeIDBFactory {
 
         await transaction._waitDone();
 
-        // We don't explicitly exit the versionchange transaction,
-        // since this is already done by the BridgeIDBTransaction.
-        db._upgradeTransaction = null;
-
         // We re-use the same transaction (as per spec) here.
         transaction._active = true;
 
@@ -2425,6 +2421,11 @@ export class BridgeIDBTransaction
       if (this._backendTransaction) {
         await this._backend.commit(this._backendTransaction);
       }
+
+      // We must exit the upgrade transaction here, so that the "complete"
+      // event handler can already do other transactions.
+      this._db._upgradeTransaction = null;
+
       this._committed = true;
       if (!this._error) {
         if (BridgeIDBFactory.enableTracing) {
diff --git a/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts 
b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
index 2f1797a6..7da0ea8f 100644
--- a/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
+++ b/packages/idb-bridge/src/idb-wpt-ported/cursor-overloads.test.ts
@@ -1,11 +1,15 @@
 import test from "ava";
-import { BridgeIDBCursor } from "..";
+import { BridgeIDBCursor, BridgeIDBKeyRange } from "..";
 import { BridgeIDBCursorWithValue } from "../bridge-idb";
+import { IDBRequest } from "../idbtypes";
 import { createdb } from "./wptsupport";
 
-// Validate the overloads of IDBObjectStore.openCursor(), 
IDBIndex.openCursor() and IDBIndex.openKeyCursor()
+const IDBKeyRange = BridgeIDBKeyRange;
+
+// Validate the overloads of IDBObjectStore.openCursor(),
+// IDBIndex.openCursor() and IDBIndex.openKeyCursor()
 test.cb("WPT test cursor-overloads.htm", (t) => {
-  var db: any, trans: any, store: any, index: any;
+  var db: any, store: any, index: any;
 
   var request = createdb(t);
   request.onupgradeneeded = function (e) {
@@ -13,102 +17,107 @@ test.cb("WPT test cursor-overloads.htm", (t) => {
     store = db.createObjectStore("store");
     index = store.createIndex("index", "value");
     store.put({ value: 0 }, 0);
-    trans = request.transaction;
+    const trans = request.transaction!;
     trans.oncomplete = verifyOverloads;
   };
 
-  function verifyOverloads() {
-    trans = db.transaction("store");
+  async function verifyOverloads() {
+    const trans = db.transaction("store");
     store = trans.objectStore("store");
     index = store.index("index");
 
-    checkCursorDirection("store.openCursor()", "next");
-    checkCursorDirection("store.openCursor(0)", "next");
-    checkCursorDirection("store.openCursor(0, 'next')", "next");
-    checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
-    checkCursorDirection("store.openCursor(0, 'prev')", "prev");
-    checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");
+    await checkCursorDirection(store.openCursor(), "next");
+    await checkCursorDirection(store.openCursor(0), "next");
+    await checkCursorDirection(store.openCursor(0, 'next'), "next");
+    await checkCursorDirection(store.openCursor(0, 'nextunique'), 
"nextunique");
+    await checkCursorDirection(store.openCursor(0, 'prev'), "prev");
+    await checkCursorDirection(store.openCursor(0, 'prevunique'), 
"prevunique");
 
-    checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
-    checkCursorDirection(
-      "store.openCursor(IDBKeyRange.only(0), 'next')",
+    await checkCursorDirection(store.openCursor(IDBKeyRange.only(0)), "next");
+    await checkCursorDirection(
+      store.openCursor(BridgeIDBKeyRange.only(0), 'next'),
       "next",
     );
-    checkCursorDirection(
-      "store.openCursor(IDBKeyRange.only(0), 'nextunique')",
+    await checkCursorDirection(
+      store.openCursor(IDBKeyRange.only(0), 'nextunique'),
       "nextunique",
     );
-    checkCursorDirection(
-      "store.openCursor(IDBKeyRange.only(0), 'prev')",
+    await checkCursorDirection(
+      store.openCursor(IDBKeyRange.only(0), 'prev'),
       "prev",
     );
-    checkCursorDirection(
-      "store.openCursor(IDBKeyRange.only(0), 'prevunique')",
+    await checkCursorDirection(
+      store.openCursor(IDBKeyRange.only(0), 'prevunique'),
       "prevunique",
     );
 
-    checkCursorDirection("index.openCursor()", "next");
-    checkCursorDirection("index.openCursor(0)", "next");
-    checkCursorDirection("index.openCursor(0, 'next')", "next");
-    checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
-    checkCursorDirection("index.openCursor(0, 'prev')", "prev");
-    checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");
+    await checkCursorDirection(index.openCursor(), "next");
+    await checkCursorDirection(index.openCursor(0), "next");
+    await checkCursorDirection(index.openCursor(0, 'next'), "next");
+    await checkCursorDirection(index.openCursor(0, 'nextunique'), 
"nextunique");
+    await checkCursorDirection(index.openCursor(0, 'prev'), "prev");
+    await checkCursorDirection(index.openCursor(0, 'prevunique'), 
"prevunique");
 
-    checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
-    checkCursorDirection(
-      "index.openCursor(IDBKeyRange.only(0), 'next')",
+    await checkCursorDirection(index.openCursor(IDBKeyRange.only(0)), "next");
+    await checkCursorDirection(
+      index.openCursor(IDBKeyRange.only(0), 'next'),
       "next",
     );
-    checkCursorDirection(
-      "index.openCursor(IDBKeyRange.only(0), 'nextunique')",
+    await checkCursorDirection(
+      index.openCursor(IDBKeyRange.only(0), 'nextunique'),
       "nextunique",
     );
-    checkCursorDirection(
-      "index.openCursor(IDBKeyRange.only(0), 'prev')",
+    await checkCursorDirection(
+      index.openCursor(IDBKeyRange.only(0), 'prev'),
       "prev",
     );
-    checkCursorDirection(
-      "index.openCursor(IDBKeyRange.only(0), 'prevunique')",
+    await checkCursorDirection(
+      index.openCursor(IDBKeyRange.only(0), 'prevunique'),
       "prevunique",
     );
 
-    checkCursorDirection("index.openKeyCursor()", "next");
-    checkCursorDirection("index.openKeyCursor(0)", "next");
-    checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
-    checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
-    checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
-    checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");
+    await checkCursorDirection(index.openKeyCursor(), "next");
+    await checkCursorDirection(index.openKeyCursor(0), "next");
+    await checkCursorDirection(index.openKeyCursor(0, 'next'), "next");
+    await checkCursorDirection(index.openKeyCursor(0, 'nextunique'), 
"nextunique");
+    await checkCursorDirection(index.openKeyCursor(0, 'prev'), "prev");
+    await checkCursorDirection(index.openKeyCursor(0, 'prevunique'), 
"prevunique");
 
-    checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
-    checkCursorDirection(
-      "index.openKeyCursor(IDBKeyRange.only(0), 'next')",
+    await checkCursorDirection(index.openKeyCursor(IDBKeyRange.only(0)), 
"next");
+    await checkCursorDirection(
+      index.openKeyCursor(IDBKeyRange.only(0), 'next'),
       "next",
     );
-    checkCursorDirection(
-      "index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')",
+    await checkCursorDirection(
+      index.openKeyCursor(IDBKeyRange.only(0), 'nextunique'),
       "nextunique",
     );
-    checkCursorDirection(
-      "index.openKeyCursor(IDBKeyRange.only(0), 'prev')",
+    await checkCursorDirection(
+      index.openKeyCursor(IDBKeyRange.only(0), 'prev'),
       "prev",
     );
-    checkCursorDirection(
-      "index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')",
+    await checkCursorDirection(
+      index.openKeyCursor(IDBKeyRange.only(0), 'prevunique'),
       "prevunique",
     );
 
     t.end();
   }
 
-  function checkCursorDirection(statement: string, direction: string) {
-    request = eval(statement);
-    request.onsuccess = function (event: any) {
-      t.notDeepEqual(event.target.result, null, "Check the result is not 
null");
-      t.deepEqual(
-        event.target.result.direction,
-        direction,
-        "Check the result direction",
-      );
-    };
+  function checkCursorDirection(
+    request: IDBRequest,
+    direction: string,
+  ): Promise<void> {
+    return new Promise<void>((resolve, reject) => {
+      request.onsuccess = function (event: any) {
+        t.notDeepEqual(event.target.result, null, "Check the result is not 
null");
+        t.deepEqual(
+          event.target.result.direction,
+          direction,
+          "Check the result direction",
+        );
+        resolve();
+      };
+    });
   }
 });

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]