Skip to content

test(supabase_flutter): deflake the expired session stream expectation - #1720

Open
spydon wants to merge 1 commit into
mainfrom
test/deflake-expired-session-wasm
Open

test(supabase_flutter): deflake the expired session stream expectation#1720
spydon wants to merge 1 commit into
mainfrom
test/deflake-expired-session-wasm

Conversation

@spydon

@spydon spydon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Test fix for a flaky WASM CI failure on main.

What is the current behavior?

Expired session emits exception when no auto refresh waits a fixed 100ms and then asserts that the next event on onAuthStateChange is an error:

await Future.delayed(const Duration(milliseconds: 100));
await expectLater(
  Supabase.instance.client.auth.onAuthStateChange,
  emitsError(isA<AuthException>()),
);

The session recovery flow emits initialSession, then signedOut (with signOutReason: sessionExpired), and only after the logout HTTP call fails does the AuthException reach the stream. Since ReplaySubject replays only the latest event, the test passes only when the whole flow, including the HTTP roundtrip, completes within the 100ms budget. On a slow runner the subscription lands between signedOut and the error, the replayed event is a data event, and emitsError fails:

Which: emitted • AuthState(event: signedOut, session: null, fromBroadcast: false, signOutReason: sessionExpired)

This is exactly the failure seen on the main WASM runs starting with the run for #1716. The race is unrelated to that commit: reducing the delay reproduces the identical failure on 29286f4, the commit before it, and both failing CI runs executed concurrently on loaded runners while all passing runs did not.

What is the new behavior?

The test drops the fixed delay and skips past data events until the error arrives, which is deterministic for every interleaving:

await expectLater(
  Supabase.instance.client.auth.onAuthStateChange,
  emitsThrough(emitsError(isA<AuthException>())),
);

Verified locally on the VM and with flutter test --platform chrome --wasm.

Summary by CodeRabbit

  • Tests
    • Updated expired-session authentication coverage to account for intermediate sign-out events and event replay.
    • Improved validation of eventual authentication errors without relying on fixed timing delays.

@spydon
spydon requested a review from a team as a code owner August 14, 2026 14:50
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6658f34a-0c32-47ab-9ff8-df8291deefeb

📥 Commits

Reviewing files that changed from the base of the PR and between a0be827 and 4c0e4b8.

📒 Files selected for processing (1)
  • packages/supabase_flutter/test/supabase_flutter_test.dart

📝 Walkthrough

Walkthrough

The expired-session authentication stream test now skips intermediate signedOut and replay events before asserting the expected AuthException.

Changes

Auth stream test

Layer / File(s) Summary
Stream event assertion
packages/supabase_flutter/test/supabase_flutter_test.dart
The test removes the fixed delay and uses emitsThrough(emitsError(...)) to assert the eventual AuthException.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 4c0e4

This test-only change makes the expired-session assertion deterministic by tolerating intermediate state events before the expected error; no actionable merge-blocking risk remains.

Suggested reviewers: dshukertjr

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: removing flakiness from the expired-session stream expectation test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/deflake-expired-session-wasm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant