Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,21 @@ describe('importing a per-chat journal', () => {
})
)
const between: number[] = []
let copying = true
const tick = (): void => {
// What a live chat's append would commit under, between two copy batches.
between.push(synchronous())
if (copying) {
setImmediate(tick)
}
pending = setImmediate(tick)
}

setImmediate(tick)
let pending = setImmediate(tick)
await importPerSessionJournal({
database,
identity: IDENTITY,
legacyDirectory: legacyDir(),
batchRows: 1
})
copying = false
// A flag would still let the queued tick read the database after teardown closes it.
clearImmediate(pending)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Cancel the tick when the import rejects.

If importPerSessionJournal rejects, execution skips clearImmediate(pending). The queued tick then reschedules itself and continues reading the database. Put the cancellation in a finally block so a failed import cannot leave the loop running during teardown.

Proposed fix
-    await importPerSessionJournal({
-      database,
-      identity: IDENTITY,
-      legacyDirectory: legacyDir(),
-      batchRows: 1
-    })
-    // A flag would still let the queued tick read the database after teardown closes it.
-    clearImmediate(pending)
+    try {
+      await importPerSessionJournal({
+        database,
+        identity: IDENTITY,
+        legacyDirectory: legacyDir(),
+        batchRows: 1
+      })
+    } finally {
+      clearImmediate(pending)
+    }


// 2 is FULL, 1 is NORMAL.
expect(commits.slice(0, rows.length)).toEqual(rows.map(() => 1))
Expand Down
Loading