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
bin/format
bin/check
nix flake check
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.
go vet ./...
golangci-lint run
go vet ./...
golangci-lint run
+go test -race -short ./...
files '*.nix' | xargs nixfmt --check
files '*.rst' | xargs rstfmt --check
files '*.md' | xargs mdformat --check
files '*.nix' | xargs nixfmt --check
files '*.rst' | xargs rstfmt --check
files '*.md' | xargs mdformat --check
checks = forEachSystem (system: {
package = self.packages.${system}.default;
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);
});
formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt);
subPackages = [ "." ];
vendorHash = "sha256-Mpw1XigL2ARm8oTKwutBLHxdLChSfK1ZbGRaNww8jkk=";
subPackages = [ "." ];
vendorHash = "sha256-Mpw1XigL2ARm8oTKwutBLHxdLChSfK1ZbGRaNww8jkk=";
+ # The flake check runs the full replay.
+ checkFlags = [ "-short" ];
+
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
--- /dev/null
+# 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$"
+ ];
+}
"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))
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)
}
}
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())