Fix writethrough falling behind
This commit is contained in:
parent
b922fc3b00
commit
dded8beaeb
3 changed files with 36 additions and 1 deletions
|
@ -85,6 +85,34 @@ describe("writethrough", () => {
|
||||||
const output = await db.get(current._id)
|
const output = await db.get(current._id)
|
||||||
expect(output.value).toBe(4)
|
expect(output.value).toBe(4)
|
||||||
expect(output._rev).toBe(newRev)
|
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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -51,7 +51,7 @@ async function put(
|
||||||
async () => {
|
async () => {
|
||||||
const writeDb = async (toWrite: any) => {
|
const writeDb = async (toWrite: any) => {
|
||||||
// doc should contain the _id and _rev
|
// doc should contain the _id and _rev
|
||||||
const response = await db.put(toWrite)
|
const response = await db.put(toWrite, { force: true })
|
||||||
output = {
|
output = {
|
||||||
...doc,
|
...doc,
|
||||||
_id: response.id,
|
_id: response.id,
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
|
import { structures } from ".."
|
||||||
import { newid } from "../../../src/newid"
|
import { newid } from "../../../src/newid"
|
||||||
|
|
||||||
export function id() {
|
export function id() {
|
||||||
return `db_${newid()}`
|
return `db_${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rev() {
|
||||||
|
return `${structures.generator.character({
|
||||||
|
numeric: true,
|
||||||
|
})}-${structures.uuid().replace(/-/, "")}`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue