-
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the test even more naughty by spawning async function.
Removed the old test that never reproduced anything.
- Loading branch information
1 parent
d3d28a0
commit 200bf86
Showing
1 changed file
with
12 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,9 +435,17 @@ promisedTest("Issue - ReadonlyError thrown in liveQuery despite user did not do | |
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; | ||
const result = await db.metrics.toArray(); | ||
//await 3; | ||
async function foo() { | ||
console.log("qm PSD.id = " + Dexie.Promise.PSD?.id); | ||
await db.metrics.toArray(); | ||
console.log("qm PSD.id = " + Dexie.Promise.PSD?.id); | ||
} | ||
foo(); // Be naughty and spawn promises that we don't await. | ||
// Verify that we handle this situation and escape from zone echoing before | ||
// we return the result. | ||
return result; | ||
}); | ||
equal(Dexie.Promise.PSD.id, 'global', "PSD is the global PSD"); | ||
|
@@ -446,6 +454,7 @@ promisedTest("Issue - ReadonlyError thrown in liveQuery despite user did not do | |
await new Promise(resolve => { | ||
const o = observable.subscribe(val => { | ||
o.unsubscribe(); | ||
console.log("PSD.id = " + Dexie.Promise.PSD?.id); | ||
resolve(val); | ||
}); | ||
}); | ||
|
@@ -457,57 +466,3 @@ promisedTest("Issue - ReadonlyError thrown in liveQuery despite user did not do | |
`); | ||
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 | ||
* multiple liveQueries and transactions running in parallel. | ||
* However, the issue is fixed with this same commit which will be | ||
* [email protected]. It is verified with customer application. | ||
* | ||
* Keeping the test in case there will be time to try to improve it later. | ||
*/ | ||
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 ()=>{ | ||
let physicalTickScheduled = false; | ||
const observable = liveQuery(async () => { | ||
console.debug("liveQuery executing"); | ||
//debugger; | ||
const result = db.transaction('r', 'metrics', async () => db.metrics.toArray()); | ||
physicalTickScheduled = true; | ||
console.debug("physicalTick executed by toArray"); | ||
return await result; | ||
}); | ||
const subscription = observable.subscribe({ | ||
next: function (result) { | ||
ok(true, "Got next result from observable"); | ||
} | ||
}); | ||
ok(!!physicalTickScheduled, "physicalTick is scheduled at this point"); | ||
console.debug("liveQuery subscribed. Now doing transaction immediately - it will push to microtickQueue"); | ||
try { | ||
//debugger; | ||
//db.transaction('rw', db.metrics, () => { | ||
// const x = Promise.PSD; | ||
await db.metrics.add({ id: "id1", name: "a", time: 1 }).then(() => { | ||
//debugger; | ||
return db.metrics.update("id1", {name: "b"}); | ||
}); | ||
//}); | ||
console.debug("Transaction succeeded"); | ||
ok(true, "Successfully executed transaction"); | ||
} catch (error) { | ||
console.debug("Transaction failed"); | ||
ok(false, 'Failed to execute transaction due to ' + error); | ||
} | ||
subscription.unsubscribe(); | ||
})(); | ||
`); | ||
return F(ok, equal, Dexie, db, liveQuery).catch(err => ok(false, 'final catch: '+err)); | ||
}); |