ably / ably-chat-js

Ably Chat SDK for JavaScript to build chat experiences at scale
https://ably-livestream-chat-demo.vercel.app/
Apache License 2.0
8 stars 0 forks source link

react/presence: fix flakey test with usePresence #376

Closed AndyTWF closed 1 week ago

AndyTWF commented 1 week ago

Context

N/A

Description

This change fixes the usePresence integration test. It was flaking because a leave and detach in quick succession (as the test does via unmounting) can lead to duplicate presence events as realtime will do an implicit leave for any detachments it deems still in presence.

This would lead to the presence events array having 4 events (instead of the expected 3).

The fix is to assert on seeing specific presence events we expect to see, showing that we get the desired behaviour, but without falling over because of potential race conditions.

It also fixes the messages.integration.test during the transitional period to using per-message serials.

Checklist

Testing Instructions (Optional)

Run the test with many repeats and observe the lack of flakeyness!

github-actions[bot] commented 1 week ago

Coverage Report

Status Category Percentage Covered / Total
🟒 Lines 92.63% (🎯 92%) 2728 / 2945
🟒 Statements 92.63% (🎯 92%) 2728 / 2945
🟒 Functions 92.57% (🎯 92%) 212 / 229
🟒 Branches 94.02% (🎯 93%) 771 / 820
File CoverageNo changed files found.
Generated in workflow #1614 for commit 285a088 by the Vitest Coverage Report Action