Skip to content

Commit

Permalink
presenceEnterUpdate: fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonWoolf committed Nov 28, 2024
1 parent b18a35a commit 3cb1699
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions test/realtime/presence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,34 +568,20 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
*
* @spec RTP10
*/
it('presenceEnterAndLeave', function (done) {
it('presenceEnterAndLeave', async function () {
const helper = this.test.helper;
var channelName = 'enterAndLeave';
var enterAndLeave = function (cb) {
var clientRealtime = helper.AblyRealtime({ clientId: testClientId, tokenDetails: authToken });
clientRealtime.connection.on('connected', function () {
/* get channel, attach, and enter */
var clientChannel = clientRealtime.channels.get(channelName);
Helper.whenPromiseSettles(clientChannel.attach(), function (err) {
if (err) {
cb(err, clientRealtime);
return;
}
Helper.whenPromiseSettles(clientChannel.presence.enter('Test client data (leave0)'), function (err) {
if (err) {
cb(err, clientRealtime);
return;
}
});
Helper.whenPromiseSettles(clientChannel.presence.leave(), function (err) {
cb(err, clientRealtime);
});
});
});
helper.monitorConnection(done, clientRealtime);
};

runTestWithEventListener(done, helper, channelName, listenerFor('leave'), enterAndLeave);
const channelName = 'enterAndLeave';
const clientRealtime = helper.AblyRealtime({ clientId: testClientId, tokenDetails: authToken });
await clientRealtime.connection.whenState('connected');
/* get channel, attach, and enter */
const clientChannel = clientRealtime.channels.get(channelName);
await clientChannel.attach();
await Promise.all([
clientChannel.presence.enter('Test client data (leave0)'),
clientChannel.presence.subscriptions.once('enter'),
]);
await Promise.all([clientChannel.presence.leave(), clientChannel.presence.subscriptions.once('leave')]);
clientRealtime.close();
});

/**
Expand Down

0 comments on commit 3cb1699

Please sign in to comment.