Skip to content

Fix FakeAsync usage in last_online_reporting tests#2137

Open
nilsreichardt wants to merge 1 commit intomainfrom
codex/fix-fakeasync-tests-always-passing
Open

Fix FakeAsync usage in last_online_reporting tests#2137
nilsreichardt wants to merge 1 commit intomainfrom
codex/fix-fakeasync-tests-always-passing

Conversation

@nilsreichardt
Copy link
Member

Motivation

  • Tests using FakeAsync were effectively passing unconditionally because microtasks and debounced timers were not driven correctly, hiding regressions.
  • The tests also used an inconsistent debounce duration which made them harder to reason about.

Description

  • Use a single debounceTime constant and pass it into LastOnlineReporter.internal so tests and setup are consistent.
  • Run FakeAsync().run with synchronous closures and explicitly call fakeAsync.flushMicrotasks() and fakeAsync.elapse(...) to properly drive timers and microtasks.
  • Trigger the backend error path in the crash-logging test by setting backend.shouldThrow = true and replace pumpEventQueue/async awaits with flushMicrotasks or hasListener checks to validate subscription cleanup.

Testing

  • Executed fvm flutter test lib/last_online_reporting/test/last_online_reporting_test.dart and all tests passed.

Codex Task

@nilsreichardt nilsreichardt added the codex Used for PRs that are generated by Codex. label Feb 3, 2026 — with ChatGPT Codex Connector
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 104 to +105
lastOnlineReporter.startReporting();
await pumpEventQueue();
expect(lifecycleChanges.hasListener, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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().

Suggested change
lastOnlineReporter.startReporting();
await pumpEventQueue();
expect(lifecycleChanges.hasListener, true);
lastOnlineReporter.startReporting();
fakeAsync.flushMicrotasks();
expect(lifecycleChanges.hasListener, true);

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

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

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

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

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Used for PRs that are generated by Codex. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant