Skip to content

test: run logmq tests on a fake clock - #1168

Merged
alexluong merged 3 commits into
mainfrom
test/fake-clock-logmq
Oct 29, 2026
Merged

alexluong merged 3 commits into
mainfrom
test/fake-clock-logmq

Conversation

@alexluong

@alexluong alexluong commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Run the logmq tests on a fake clock. Based on #1162.

The logmq tests waited real time for batch delays and emit timeouts: fixed 200 ms sleeps for a batch to flush, and require.Eventually polls for sends, evaluations and acks to land. Now they run inside a synctest bubble, with Redis from testutil.NewSynctestRedis where they need it, so those waits cost nothing and the checks no longer depend on CPU load.

The package now runs in under 1 s.

  1. batchprocessor_test.go: the tests run in a bubble, except TestMessageHandler_NacksAfterShutdown, which has no waits. The 200 ms sleeps that waited for a flush become synctest.Wait().
  2. The characterization harness, the tests using it and the suppression window tests run in a bubble with an in-memory Redis. require.Eventually polls become synctest.Wait() plus a direct assert.
    • waitTerminal steps the fake clock 1 ms at a time until every message is acked or nacked, so batch delays and emit timeouts elapse without real waiting.
    • waitBlocked returns once a send is parked on the blocking sink, with no poll.

Assertions are kept; some are stricter. A flush asserted after synctest.Wait() has to happen without the clock moving, where the 200 ms sleep allowed up to 200 ms. TestRedisSuppressionWindow_InFlightCallerSkipsWithoutWaiting asserts zero elapsed time instead of under 100 ms.

The package was stress-tested with repeated runs, plain, with -race, and with -cpu=1,2 and -shuffle=on.

🤖 Generated with Claude Code


// Wait until the delivery is actually blocked inside the sink.
synctest.Wait()
require.True(t, h.sink.inflightSends() >= 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the old Eventually here had the message "the slow delivery should reach the sink". require.GreaterOrEqual(t, h.sink.inflightSends(), 1, "...") would keep it and print the actual count on failure. Same for :88 and characterization_postprocess_test.go:39, which also lost their messages, and the other require.True(... >= n) checks would get the count too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated. All six now use GreaterOrEqual, with the old messages restored where they had one.

Base automatically changed from test/fake-clock-redis to main October 29, 2026 12:21
alexluong and others added 3 commits October 29, 2026 19:22
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexluong
alexluong force-pushed the test/fake-clock-logmq branch from 98d21e2 to bc80c58 Compare October 29, 2026 12:23
@alexluong
alexluong merged commit 70e00e3 into main Oct 29, 2026
1 check passed
@alexluong
alexluong deleted the test/fake-clock-logmq branch October 29, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants