Fix FakeAsync usage in last_online_reporting tests#2137
Fix FakeAsync usage in last_online_reporting tests#2137nilsreichardt wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request significantly improves the reliability of tests for LastOnlineReporter by correcting the usage of FakeAsync. The changes properly use flushMicrotasks and elapse to manage asynchronous operations in tests, remove incorrect async/await patterns, and fix logic errors that caused tests to pass unconditionally. Using a constant for the debounce time also improves consistency. Overall, these are excellent changes that make the test suite more robust. The minor suggestion provided is still valid.
| lastOnlineReporter.startReporting(); | ||
| await pumpEventQueue(); | ||
| expect(lifecycleChanges.hasListener, true); |
There was a problem hiding this comment.
For consistency with the other tests in this file, it's good practice to flush microtasks after calling startReporting() to ensure any initial events are processed before proceeding with the test's assertions. This also makes the test more robust against future changes to startReporting().
| lastOnlineReporter.startReporting(); | |
| await pumpEventQueue(); | |
| expect(lifecycleChanges.hasListener, true); | |
| lastOnlineReporter.startReporting(); | |
| fakeAsync.flushMicrotasks(); | |
| expect(lifecycleChanges.hasListener, true); |
|
Visit the preview URL for this PR (updated for commit 11bf1f1): https://sharezone-console-dev--pr2137-codex-fix-fakeasync-ajkcv8ai.web.app (expires Fri, 06 Feb 2026 21:24:40 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 471536afe3f6ec4895d9ea75513730b515d17eb6 |
|
Visit the preview URL for this PR (updated for commit 11bf1f1): https://sharezone-website-dev--pr2137-codex-fix-fakeasync-okx0xxzz.web.app (expires Fri, 06 Feb 2026 21:25:54 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 372b0431a96247f908d9a97d5d865de1c8b3b04e |
|
Visit the preview URL for this PR (updated for commit 11bf1f1): https://sharezone-test--pr2137-codex-fix-fakeasync-v5j9g1pt.web.app (expires Fri, 06 Feb 2026 21:26:33 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b |
Motivation
FakeAsyncwere effectively passing unconditionally because microtasks and debounced timers were not driven correctly, hiding regressions.Description
debounceTimeconstant and pass it intoLastOnlineReporter.internalso tests and setup are consistent.FakeAsync().runwith synchronous closures and explicitly callfakeAsync.flushMicrotasks()andfakeAsync.elapse(...)to properly drive timers and microtasks.backend.shouldThrow = trueand replacepumpEventQueue/async awaits withflushMicrotasksorhasListenerchecks to validate subscription cleanup.Testing
fvm flutter test lib/last_online_reporting/test/last_online_reporting_test.dartand all tests passed.Codex Task