Repository navigation
Fix clear() on sessions with dependencies losing later blocks #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3f8a840
a90b88b
f2115d7
b85e8ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -288,3 +288,26 @@ async function consumeStream(rx) { | |||||||||
| for await (const b of rx) res.push(b) | ||||||||||
| return res | ||||||||||
| } | ||||||||||
|
|
||||||||||
| test('clear on a session with dependencies keeps the blocks after the range', async function (t) { | ||||||||||
| const a = await create(t) | ||||||||||
| await a.append(['1', '2', '3', '4', '5']) | ||||||||||
|
|
||||||||||
| const s = a.session({ name: 'batch' }) | ||||||||||
| await s.ready() | ||||||||||
|
|
||||||||||
| await s.clear(1, 2) | ||||||||||
|
|
||||||||||
| t.ok(await s.has(0), 'block before the range is kept') | ||||||||||
| t.is(await s.has(1), false, 'block in the range is cleared') | ||||||||||
| t.ok(await s.has(2), 'block at the end of the range is kept (end is exclusive)') | ||||||||||
| t.ok(await s.has(3), 'block after the range is kept') | ||||||||||
| t.ok(await s.has(s.length - 1), 'last block is kept') | ||||||||||
| t.alike(await s.get(2), b4a.from('3'), 'block at the end boundary still resolves') | ||||||||||
| t.alike(await s.get(4), b4a.from('5'), 'last block still resolves') | ||||||||||
|
Comment on lines
+306
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test uses waiting
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: test/clear.js
Line: 306-307
Comment:
**Missing blocks stall the test**
The new test uses waiting `get()` calls to check local blocks. If the regression returns, a missing block makes `get()` wait for replication with no request timeout, and this test has no peers. Pass `{ wait: false }` to these reads so missing blocks produce assertion failures instead of unfinished checks.
```suggestion
t.alike(await s.get(2, { wait: false }), b4a.from('3'), 'block at the end boundary still resolves')
t.alike(await s.get(4, { wait: false }), b4a.from('5'), 'last block still resolves')
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||||||||||
|
|
||||||||||
| t.ok(await a.has(3), 'default session is unaffected') | ||||||||||
| t.alike(await a.get(4), b4a.from('5'), 'default session block still resolves') | ||||||||||
|
|
||||||||||
| await s.close() | ||||||||||
| }) | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing a small range near the start of a large named session now reads every later index and holds all returned blocks in memory at once. Sparse sessions also create a read and promise for every missing index.
Use
createBlockStream()and bounded batches to stage the copies before applying the clear and shortening the dependency.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!