"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))
- memory, err := openMemory(t.Context(), root, clock.Now, newFakeSummarizer())
+ memory, err := openMemory(t.Context(), root, clock.Now, newFakeSummarizer(), discardLog())
require.NoError(t, err)
defer func() {
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)
}
}
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())
require.NoError(t, err)
require.NoError(t, memory.Close())
- memory, err = openMemory(t.Context(), root, clock.Now, newFakeSummarizer())
+ memory, err = openMemory(t.Context(), root, clock.Now, newFakeSummarizer(), discardLog())
require.NoError(t, err)
require.NoError(t, memory.Wait(t.Context()))
require.Equal(t, view, memory.View())