test: deterministic broadcast batching/ordering tests via fakeAsync#37
Merged
Conversation
Loon schedules broadcasts on a zero-duration timer so writes in one event-loop task are delivered as a single update. Testing that with real time is inherently racy (it depends on a real timer firing before the test's wait), which is a known source of flakiness in the suite. These tests run under fakeAsync: virtual time is advanced explicitly so the broadcast timer and its microtask stream delivery fire deterministi- cally before each assertion, independent of wall-clock scheduling or CPU load. They cover broadcast batching (many writes -> one emission), create+update coalescing, per-task broadcast separation, and that a no-op update does not rebroadcast. A dedicated file runs in its own test isolate, so the global store starts clean and these virtual-time tests are isolated from the rest of the suite. fake_async is pulled in via flutter_test.
There was a problem hiding this comment.
Pull request overview
Adds a new deterministic test suite to validate Loon’s broadcast batching/coalescing behavior by advancing virtual time with fakeAsync, avoiding wall-clock timing races and reducing test flakiness around zero-duration broadcast scheduling.
Changes:
- Adds a dedicated
fakeAsync-based test file covering batching, coalescing, per-task separation, and no-op suppression. - Introduces small helpers to reset the global store and advance virtual time between assertions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+4
| // ignore_for_file: depend_on_referenced_packages | ||
| import 'package:fake_async/fake_async.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:loon/loon.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds deterministic tests for broadcast batching, coalescing, and ordering using
fakeAsync.Loon schedules a broadcast on a zero-duration timer so that all writes in a single event-loop task are delivered to observers as one update. Verifying that behaviour with real time is inherently racy — it depends on a real timer firing before the test's
await— which is a known source of flakiness in the suite. These tests advance virtual time explicitly, so the broadcast timer and its microtask stream delivery fire deterministically before each assertion, with no dependence on wall-clock scheduling or CPU load.What's covered
Each test runs inside a single
fakeAsynczone, and the file gets its own test isolate (so the global store starts clean and these virtual-time tests are isolated from the rest of the suite). Verified deterministic across repeated runs.Context / scope
This is the additive half of the "fakeAsync" hardening item: new deterministic ordering tests. I deliberately did not convert the existing real-async suite to fakeAsync. Investigation showed the suite's intermittent failures aren't purely a timing race — there's a cross-test state-bleed component (resetting the global store between tests schedules a broadcast that can race the next test) that a fakeAsync conversion wouldn't cleanly fix, and a wholesale rewrite of a working suite is high-risk for a flake that's already mitigated in CI (
--concurrency=1+ re-kick). The deterministic delete+recreate-coalescing case lives with its fix in #36.Test plan
flutter test test/core/broadcast_timing_test.dart— 4 tests green; deterministic across 5+ repeated runsflutter analyzeclean on the new fileflutter test test/core— greenGenerated by Claude Code