]> git.giacomolli.uk - onechat/commitdiff
Run a short replay outside the flake check
authorAnderson A. Giacomolli <redacted>
Sun, 8 Nov 2026 12:23:29 +0000 (09:23 -0300)
committerAnderson A. Giacomolli <redacted>
Sun, 8 Nov 2026 12:23:29 +0000 (09:23 -0300)
The replay of the synthetic log runs 5,000 messages with -short and
100,000 messages without it. bin/check and the test run of nix build
pass -short, so bin/check takes about 20 seconds instead of more than
two minutes under the race detector. A new flake check runs only
TestReplaySyntheticLog without -short, so nix flake check still runs the
full replay and does not run the other tests a second time.

The test uses testing.Short, because -short is the standard Go flag to
make long tests shorter, and go test and buildGoModule pass it without
new code. An environment variable would need its own name and parsing
for the same result. The short replay gives the chat view 26 batches,
and the test still requires at least one batch.

Issue: e4109b7

README.rst
bin/check
flake.nix
nix/package.nix
nix/replay.nix [new file with mode: 0644]
replay_test.go

index c9aaaeeb4e1b59fa0e4ac307118508f7d7c4010f..e386c67566cacb7e0267bd651ed662a59bc24e0e 100644 (file)
@@ -203,3 +203,6 @@ Format and check all files:
    bin/format
    bin/check
    nix flake check
+
+``bin/check`` and ``nix build`` run a short replay of the synthetic log.
+``nix flake check`` also runs the full replay of 100,000 messages.
index b8071dce37734bdbefa1586acc4ac2b949f89501..3bca02623eb87d6b8720e944e01be5de2e0e4b9b 100755 (executable)
--- a/bin/check
+++ b/bin/check
@@ -15,7 +15,7 @@ fi
 
 go vet ./...
 golangci-lint run
-go test -race ./...
+go test -race -short ./...
 files '*.nix' | xargs nixfmt --check
 files '*.rst' | xargs rstfmt --check
 files '*.md' | xargs mdformat --check
index b15cd5b16775a60f13bf217a5be560f45798c21f..f21a609f6fe3d0fc47a323e66a6b21c305790bc5 100644 (file)
--- a/flake.nix
+++ b/flake.nix
@@ -36,6 +36,7 @@
 
       checks = forEachSystem (system: {
         package = self.packages.${system}.default;
+        replay = import ./nix/replay.nix { onechat = self.packages.${system}.default; };
       });
 
       formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt);
index 20bb05377018e24e43b08b6133b5d5cf079838d2..ceb629f34e9dc325a63dbda065bda053ade3341a 100644 (file)
@@ -11,6 +11,9 @@ buildGoModule {
   subPackages = [ "." ];
   vendorHash = "sha256-Mpw1XigL2ARm8oTKwutBLHxdLChSfK1ZbGRaNww8jkk=";
 
+  # The flake check runs the full replay.
+  checkFlags = [ "-short" ];
+
   doInstallCheck = true;
   installCheckPhase = ''
     runHook preInstallCheck
diff --git a/nix/replay.nix b/nix/replay.nix
new file mode 100644 (file)
index 0000000..f098456
--- /dev/null
@@ -0,0 +1,10 @@
+# Runs only the full replay of the synthetic log. The package runs it with
+# -short, together with the other tests.
+{ onechat }:
+onechat.overrideAttrs {
+  pname = "onechat-replay";
+  checkFlags = [
+    "-v"
+    "-run=^TestReplaySyntheticLog$"
+  ];
+}
index 8dd54ab5b0f07a541edc87fefd070108864fc0e0..dfbe6157a78014be1036fbd9a655ae258f2c3e8c 100644 (file)
@@ -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())