Skip to content

Commit

Permalink
Repro of zone leakage from live queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Nov 29, 2023
1 parent f8a0962 commit d3d28a0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/tests-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,42 @@ promisedTest("Issue #1333 - uniqueKeys on virtual index should produce unique re
ok(result.length === 2, `Unexpected array length ${result.length} from uniqueKeys on virtual index, expected 2. Got ${result.join(',')}`);
});

/** Reproduce customer issue where ReadonlyError was thrown when using liveQuery.
*/
promisedTest("Issue - ReadonlyError thrown in liveQuery despite user did not do write transactions", async () => {
// Encapsulating the code in a string to avoid transpilation. We need native await here to trigger bug.
ok(!Promise.PSD, "Must not be within async context when starting");
ok(db.isOpen(), "DB must be open when starting");
await new Promise(resolve => setTimeout(resolve, 10));
const F = new Function('ok', 'equal', 'Dexie', 'db', 'liveQuery', `
ok(true, "Got here");
return (async ()=>{
equal(Dexie.Promise.PSD.id, 'global', "PSD is the global PSD");
const observable = liveQuery(async () => {
console.debug("liveQuery executing");
const result = db.metrics.toArray();
console.debug("physicalTick executed by toArray");
return await result;
});
equal(Dexie.Promise.PSD.id, 'global', "PSD is the global PSD");
ok(true, "Now awaiting promise subscribing to liveQuery observable");
console.log("before await in global");
await new Promise(resolve => {
const o = observable.subscribe(val => {
o.unsubscribe();
resolve(val);
});
});
console.log("after await in global");
console.log("Got result from observable");
equal(Dexie.Promise.PSD.id, "global", "PSD is still the global PSD");
await db.transaction('rw', db.metrics, () => {}); // Fails if we're in a liveQuery zone
})();
`);
return F(ok, equal, Dexie, db, liveQuery).catch(err => ok(false, 'final catch: '+err));
});

/** Try to reproduce customer issue where ReadonlyError was thrown when using liveQuery.
* This repro is not good enough though as it doesn't fail in [email protected].
* Probably need to reproduce it in a more complex scenario with
Expand Down

0 comments on commit d3d28a0

Please sign in to comment.