]> git.giacomolli.uk - onechat/blobdiff - replay_test.go
Share the request chain of a turn
[onechat] / replay_test.go
index 8dd54ab5b0f07a541edc87fefd070108864fc0e0..dfbe6157a78014be1036fbd9a655ae258f2c3e8c 100644 (file)
@@ -13,16 +13,28 @@ import (
        "github.com/stretchr/testify/require"
 )
 
        "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
 
 // 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()
 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))
        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
 
        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)
                }
 
@@ -58,11 +70,11 @@ func TestReplaySyntheticLog(t *testing.T) {
        }
 
        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()))
        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())
 
        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())