ably-java icon indicating copy to clipboard operation
ably-java copied to clipboard

Fix more flakey tests

Open AndyTWF opened this issue 2 years ago • 0 comments

RealtimeChannel: attach_when_channel_in_detaching_state

The test was failing/flakey because the channel sometimes quickly cycled through detaching into attaching, before the listener had a chance to check the state.

This change fixes the issue by making the assertion via a channel state listener instead of a point-in-time check of the channel state, which means transient states are also recorded.

Fixes #944

RealtimeChannelTest channel_resume_lost_continuity

This test was failing because of the order in which listeners were registered. The channel waiters were created (and thus registered as listeners) before the listeners that add state changes to the arrays ready for assertions. EventEmitter runs listeners that don't have a filter in order of registration.

This meant that sometimes, the test would run, the waiter would be informed of a channel state change, thus allowing it to proceed into the assertions phase on the main thread, and only then would the subjects of those assertions be updated.

So you can end up in a situation where the main thread would start asserting on things before all the listeners had run.

This change fixes the issue by ensuring the waiters are registered after the main listeners, so that the assertions will always run once all the states that are going to be received, are received.

You can test this behaviour by adding a sleep just before the line where attachingStateReached[0] is set to true. If you remove the change in this commit, the test will fail.

Fixes #945

AndyTWF avatar May 24 '23 10:05 AndyTWF