From: Anderson A. Giacomolli Date: Sun, 8 Nov 2026 12:23:29 +0000 (-0300) Subject: Run a short replay outside the flake check X-Git-Url: https://git.giacomolli.uk/onechat/commitdiff_plain/9bd91a76e6277f7716e206ddb665dc5fe6f5b583?hp=5bb22ac2fc501bad7327c119f1d3ac514e3d5398 Run a short replay outside the flake check 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 --- diff --git a/README.rst b/README.rst index c9aaaee..e386c67 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/bin/check b/bin/check index b8071dc..3bca026 100755 --- 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 diff --git a/flake.nix b/flake.nix index b15cd5b..f21a609 100644 --- 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); diff --git a/nix/package.nix b/nix/package.nix index 20bb053..ceb629f 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -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 index 0000000..f098456 --- /dev/null +++ b/nix/replay.nix @@ -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$" + ]; +} 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())