1
0
Fork 0
mirror of synced 2024-07-10 16:55:46 +12:00

Fix writethrough falling behind

This commit is contained in:
adrinr 2023-03-01 13:16:57 +01:00
parent b922fc3b00
commit dded8beaeb
3 changed files with 36 additions and 1 deletions

View file

@ -85,6 +85,34 @@ describe("writethrough", () => {
const output = await db.get(current._id)
expect(output.value).toBe(4)
expect(output._rev).toBe(newRev)
current = output
})
})
it("should handle updates with documents falling behind", async () => {
await config.doInTenant(async () => {
tk.freeze(Date.now() + DELAY + 1)
const id = structures.uuid()
await writethrough.put({ _id: id, value: 1 })
const doc = await writethrough.get(id)
// Updating document
tk.freeze(Date.now() + DELAY + 1)
await writethrough.put({ ...doc, value: 2 })
// Update with the old rev value
tk.freeze(Date.now() + DELAY + 1)
const res = await writethrough.put({
...doc,
value: 3,
})
expect(res.ok).toBe(true)
const output = await db.get(id)
expect(output.value).toBe(3)
expect(output._rev).toBe(res.rev)
})
})
})

View file

@ -51,7 +51,7 @@ async function put(
async () => {
const writeDb = async (toWrite: any) => {
// doc should contain the _id and _rev
const response = await db.put(toWrite)
const response = await db.put(toWrite, { force: true })
output = {
...doc,
_id: response.id,

View file

@ -1,5 +1,12 @@
import { structures } from ".."
import { newid } from "../../../src/newid"
export function id() {
return `db_${newid()}`
}
export function rev() {
return `${structures.generator.character({
numeric: true,
})}-${structures.uuid().replace(/-/, "")}`
}