X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/442c68e1d384a7da0d9ab039704bf763a1c3ac35..d4dc9a3b10a6092d18fb30cfb36526556aa33227:/replay_test.go?ds=sidebyside diff --git a/replay_test.go b/replay_test.go index 4151d7e..f01cd63 100644 --- a/replay_test.go +++ b/replay_test.go @@ -96,19 +96,20 @@ func syntheticText(id, size int) string { return head + strings.Repeat(words, max(1, (size-len(head))/len(words))) } -// requireViews checks the views after a new message, while no build changes the -// tree. Each view is at most its high limit, and a batch merges the chat view -// to its low limit. It returns the size of the chat view and if a batch merged -// it, from the number of lines before the message. +// requireViews checks the views after a new message. Each view is at most its +// high limit, and a batch merges the chat view to its low limit. The leaf of +// the new message can be built after the append, so the sizes count it as the +// pending mark, as the append did. It returns the size of the chat view and if +// a batch merged it, from the number of lines before the message. func requireViews(t *testing.T, memory *Memory, lines int) (int, bool) { t.Helper() memory.mutex.Lock() defer memory.mutex.Unlock() - size := memory.chat.Size(memory.tree) + size := appendSize(memory.chat, memory.tree) require.LessOrEqual(t, size, chatHigh) - require.LessOrEqual(t, memory.cview.Size(memory.tree), compactionHigh) + require.LessOrEqual(t, appendSize(memory.cview, memory.tree), compactionHigh) merged := len(memory.chat.lines) < lines if merged { @@ -150,6 +151,12 @@ func requireOnlySummaries(t *testing.T, memory *Memory) { } } +// appendSize returns the size of view with its last line as the pending mark. +func appendSize(view *View, tree nodeReader) int { + last := view.lines[len(view.lines)-1] + return view.Size(tree) - lineSize(tree, last) + len(pending) +} + // viewLines returns the number of lines in the chat view of memory. func viewLines(memory *Memory) int { memory.mutex.Lock()