X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/baf7a940be8927278e3b4b87e7366cebfc16532f..ddd0a50f7b801112376d7fb27bfd05d2fc26c2fd:/replay_test.go?ds=inline diff --git a/replay_test.go b/replay_test.go index 8dd54ab..dfbe615 100644 --- a/replay_test.go +++ b/replay_test.go @@ -13,16 +13,28 @@ import ( "github.com/stretchr/testify/require" ) -// replayMessages is the length of the synthetic log. -const replayMessages = 100000 +const ( + // replayMessages is the length of the synthetic log. + replayMessages = 100000 + + // replayShortMessages is the length of the synthetic log with -short. + // It is long enough for batches of the chat view. + replayShortMessages = 5000 +) // TestReplaySyntheticLog runs a synthetic log through the memory core with the // fake summarizer. After each message it waits for the builds, as a turn does. // It checks that each view stays within its sawtooth, that no view line holds a // whole long message or a part of an unbuilt one, and that a restart in the -// middle and at the end loads the same views byte for byte. +// middle and at the end loads the same views byte for byte. With -short, the +// log is shorter, and the test still requires a batch of the chat view. func TestReplaySyntheticLog(t *testing.T) { start := time.Now() + messages := replayMessages + if testing.Short() { + messages = replayShortMessages + } + root := t.TempDir() clock := newTestClock() random := rand.New(rand.NewPCG(1, 2)) @@ -35,9 +47,9 @@ func TestReplaySyntheticLog(t *testing.T) { batches := 0 low := viewChatHigh - long := make([]bool, replayMessages) - for id := range replayMessages { - if id == replayMessages/2 { + long := make([]bool, messages) + for id := range messages { + if id == messages/2 { memory = replayRequireRestart(t, memory, root, clock) } @@ -58,11 +70,11 @@ func TestReplaySyntheticLog(t *testing.T) { } memory = replayRequireRestart(t, memory, root, clock) - require.Equal(t, replayMessages, memory.log.Len()) + require.Equal(t, messages, memory.log.Len()) require.Greater(t, batches, 0) require.NoError(t, memory.Wait(t.Context())) - t.Logf("%d messages, %d nodes, %d batches in %s", replayMessages, memory.tree.Count(), batches, time.Since(start).Round(time.Second)) + t.Logf("%d messages, %d nodes, %d batches in %s", messages, memory.tree.Count(), batches, time.Since(start).Round(time.Second)) t.Logf("chat view: %d lines, %d bytes, lowest after a batch %d bytes", len(memory.chat.lines), memory.chat.Size(), low) t.Logf("compaction view: %d lines, %d bytes", len(memory.cview.lines), memory.cview.Size())