mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(offline): a flush asked for during a running pass gets its own pass
An online edit that has to queue behind an older write to the same entity starts a flush so it goes out right after that write. When the older write was already in flight, flush() returned at once on the in-tab flag, and the running pass had read its pending rows before the new one existed. The edit then sat in the queue until the next trigger (the 30 second tick, a visibility change or a reconnect), so collaborators saw it late and a refresh in that window showed the older server value. A flush called while a pass runs now asks that pass for one more round, which it starts once it is done, next to the existing "mine wins" re-run. Each pass clears the request when it starts, so the extra rounds stay bounded by the calls made during a pass.
This commit is contained in:
@@ -120,6 +120,28 @@ describe('an online edit of a visit with an older write still queued', () => {
|
||||
expect(sentTimes()).toEqual(['07:00', '09:00'])
|
||||
})
|
||||
|
||||
it('goes out once the older one lands even when that one was already on its way', async () => {
|
||||
await queueFirst('pending')
|
||||
// The older time is in flight when the new one is made: the running pass has
|
||||
// already read its rows, so it must run once more for the new one.
|
||||
let edited: Promise<unknown> | undefined
|
||||
vi.mocked(apiClient.request).mockImplementation(async ({ data }) => {
|
||||
const sent = (data as typeof first).place_time
|
||||
if (sent === '07:00') {
|
||||
edited = assignmentRepo.setTimes(9, assignment, second)
|
||||
await edited
|
||||
}
|
||||
return { data: { assignment: { ...assignment, assignment_time: sent } } }
|
||||
})
|
||||
|
||||
await mutationQueue.flush()
|
||||
|
||||
expect(edited).toBeDefined()
|
||||
expect(assignmentsApi.updateTime).not.toHaveBeenCalled()
|
||||
expect(sentTimes()).toEqual(['07:00', '09:00'])
|
||||
expect(await offlineDb.mutationQueue.count()).toBe(0)
|
||||
})
|
||||
|
||||
it('holds a day clear behind an older clear of the same day', async () => {
|
||||
await assignmentRepo.clearDay(9, 1)
|
||||
await offlineDb.mutationQueue.toCollection().modify({ status: 'failed', attempts: 8 })
|
||||
|
||||
Reference in New Issue
Block a user