From 0bf429164d7b7cb5e0733a427ed4e50bb05dd78a Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian <lawrence@forooghian.com> Date: Tue, 11 Jun 2024 16:17:19 -0300 Subject: [PATCH] Move availableTransports and bestTransport inside helper Preparation for recording private API usage by tests (ECO-4821). --- test/common/modules/shared_helper.js | 25 +++++++++++++--------- test/realtime/auth.test.js | 14 ++++++------- test/realtime/channel.test.js | 31 ++++++++++++++-------------- test/realtime/crypto.test.js | 4 ++-- test/realtime/failure.test.js | 2 +- test/realtime/message.test.js | 6 +++--- test/realtime/reauth.test.js | 12 +++++------ test/realtime/resume.test.js | 7 +++++-- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/test/common/modules/shared_helper.js b/test/common/modules/shared_helper.js index 139213ad9..7f50db8bb 100644 --- a/test/common/modules/shared_helper.js +++ b/test/common/modules/shared_helper.js @@ -15,10 +15,6 @@ define([ var platform = clientModule.Ably.Realtime.Platform; var BufferUtils = platform.BufferUtils; var expect = chai.expect; - var availableTransports = utils.keysArray( - clientModule.Ably.Realtime.ConnectionManager.supportedTransports(clientModule.Ably.Realtime._transports), - ); - var bestTransport = availableTransports[0]; /* IANA reserved; requests to it will hang forever */ var unroutableHost = '10.255.255.1'; var unroutableAddress = 'http://' + unroutableHost + '/'; @@ -37,8 +33,6 @@ define([ loadTestData = testAppManager.loadJsonData; testResourcesPath = testAppManager.testResourcesPath; - availableTransports = availableTransports; - bestTransport = bestTransport; unroutableHost = unroutableHost; unroutableAddress = unroutableAddress; flushTestLogs = globals.flushLogs; @@ -65,6 +59,16 @@ define([ return new this(`${thisInDescribe.title} (defining ${label})`); } + get availableTransports() { + return utils.keysArray( + clientModule.Ably.Realtime.ConnectionManager.supportedTransports(clientModule.Ably.Realtime._transports), + ); + } + + get bestTransport() { + return this.availableTransports[0]; + } + displayError(err) { if (typeof err == 'string' || err == null) return err; @@ -196,9 +200,10 @@ define([ } /* testFn is assumed to be a function of realtimeOptions that returns a mocha test */ - static testOnAllTransports(name, testFn, skip) { + static testOnAllTransports(thisInDescribe, name, testFn, skip) { + const helper = this.forTestDefinition(thisInDescribe, name); var itFn = skip ? it.skip : it; - let transports = availableTransports; + let transports = helper.availableTransports; transports.forEach(function (transport) { itFn( name + '_with_' + transport + '_binary_transport', @@ -302,8 +307,8 @@ define([ } } - SharedHelper.testOnAllTransports.skip = function (name, testFn) { - SharedHelper.testOnAllTransports(name, testFn, true); + SharedHelper.testOnAllTransports.skip = function (thisInDescribe, name, testFn) { + SharedHelper.testOnAllTransports(thisInDescribe, name, testFn, true); }; SharedHelper.restTestOnJsonMsgpack.skip = function (name, testFn) { diff --git a/test/realtime/auth.test.js b/test/realtime/auth.test.js index ac5487676..61b3390fc 100644 --- a/test/realtime/auth.test.js +++ b/test/realtime/auth.test.js @@ -768,7 +768,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RSA4b1 * @specpartial RSA4b - token expired */ - Helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'auth_token_expires', function (realtimeOpts) { return function (done) { var helper = this.test.helper, clientRealtime, @@ -871,7 +871,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire * @specpartial RSA10e - obtain new token from authcallback when previous expires */ - Helper.testOnAllTransports('auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) { return function (done) { var helper = this.test.helper, realtime, @@ -919,7 +919,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire * @specpartial RSA10e - obtain new token from authcallback when previous expires */ - Helper.testOnAllTransports('auth_token_string_expiry_with_authcallback', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'auth_token_string_expiry_with_authcallback', function (realtimeOpts) { return function (done) { var helper = this.test.helper, realtime, @@ -965,7 +965,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RSA4a * @spec RSA4a2 */ - Helper.testOnAllTransports('auth_token_string_expiry_with_token', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'auth_token_string_expiry_with_token', function (realtimeOpts) { return function (done) { var helper = this.test.helper, realtime, @@ -1012,7 +1012,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RSA4a * @spec RSA4a2 */ - Helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'auth_expired_token_string', function (realtimeOpts) { return function (done) { var helper = this.test.helper, realtime, @@ -1061,7 +1061,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTC8 * @specskip */ - Helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) { + Helper.testOnAllTransports.skip(this, 'reauth_authCallback', function (realtimeOpts) { return function (done) { var helper = this.test.helper, realtime, @@ -1564,7 +1564,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async }); /** @nospec */ - Helper.testOnAllTransports('authorize_immediately_after_init', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'authorize_immediately_after_init', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var realtime = helper.AblyRealtime({ diff --git a/test/realtime/channel.test.js b/test/realtime/channel.test.js index 68c88723b..bfa7534ee 100644 --- a/test/realtime/channel.test.js +++ b/test/realtime/channel.test.js @@ -170,7 +170,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTS3c * @spec RTL16 */ - Helper.testOnAllTransports('channelinit0', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelinit0', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -207,7 +207,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @spec RTL4 */ - Helper.testOnAllTransports('channelattach0', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattach0', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -234,7 +234,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @spec RTL4 */ - Helper.testOnAllTransports('channelattach2', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattach2', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -262,6 +262,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL5 */ Helper.testOnAllTransports( + this, 'channelattach3', function (realtimeOpts) { return function (done) { @@ -301,7 +302,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @spec RTL4d */ - Helper.testOnAllTransports('channelattachempty', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattachempty', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -336,7 +337,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @spec RTL4d */ - Helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattachinvalid', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -377,7 +378,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @spec RTL6 */ - Helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'publish_no_attach', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -407,7 +408,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @specpartial RTL6b - callback which is called with an error */ - Helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattach_publish_invalid', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -441,7 +442,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * * @nospec */ - Helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'channelattach_invalid_twice', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -536,7 +537,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL4k1 * @spec RTL4m */ - Helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'attachWithChannelParamsBasicChannelsGet'; @@ -598,7 +599,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL4m * @spec RTL16 */ - Helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicSetOptions', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'attachWithChannelParamsBasicSetOptions'; @@ -652,7 +653,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL16 * @spec RTL7c */ - Helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'subscribeAfterSetOptions', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'subscribeAfterSetOptions'; @@ -728,7 +729,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async }); /** @spec RTL16a */ - Helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'setOptionsCallbackBehaviour', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'setOptionsCallbackBehaviour'; @@ -807,7 +808,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * Verify modes is ignored when params.modes is present * @nospec */ - Helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'attachWithChannelParamsModesAndChannelModes'; @@ -869,7 +870,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL4l * @spec RTL4m */ - Helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'attachWithChannelModes', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'attachWithChannelModes'; @@ -928,7 +929,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL4l * @spec RTL4m */ - Helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'attachWithChannelParamsDeltaAndModes', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var testName = 'attachWithChannelParamsDeltaAndModes'; diff --git a/test/realtime/crypto.test.js b/test/realtime/crypto.test.js index c0a988abf..2431b1c0e 100644 --- a/test/realtime/crypto.test.js +++ b/test/realtime/crypto.test.js @@ -484,14 +484,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async // Publish and subscribe, various transport, 128 and 256-bit /** @specpartial RSL5b - test aes 128 */ - Helper.testOnAllTransports('single_send_128', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'single_send_128', function (realtimeOpts) { return function (done) { single_send(done, this.test.helper, realtimeOpts, 128); }; }); /** @specpartial RSL5b - test aes 256 */ - Helper.testOnAllTransports('single_send_256', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'single_send_256', function (realtimeOpts) { return function (done) { single_send(done, this.test.helper, realtimeOpts, 256); }; diff --git a/test/realtime/failure.test.js b/test/realtime/failure.test.js index 57ed68435..8044abf01 100644 --- a/test/realtime/failure.test.js +++ b/test/realtime/failure.test.js @@ -603,7 +603,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async }); /** @specpartial RTN14d - last sentence: check that if we received a 5xx disconnected, when we try again we use a fallback host */ - Helper.testOnAllTransports('try_fallback_hosts_on_placement_constraint', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'try_fallback_hosts_on_placement_constraint', function (realtimeOpts) { return function (done) { /* Use the echoserver as a fallback host because it doesn't support * websockets, so it'll fail to connect, which we can detect */ diff --git a/test/realtime/message.test.js b/test/realtime/message.test.js index 131a1aa92..c50d81b09 100644 --- a/test/realtime/message.test.js +++ b/test/realtime/message.test.js @@ -78,7 +78,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * Test publishes in quick succession (on successive ticks of the event loop) * @spec RTL6b */ - Helper.testOnAllTransports('publishfast', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'publishfast', function (realtimeOpts) { return function (done) { const helper = this.test.helper; try { @@ -145,7 +145,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL6c2 * @specpartial RTL3d - test processing queued messages */ - Helper.testOnAllTransports('publishQueued', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'publishQueued', function (realtimeOpts) { return function (done) { var helper = this.test.helper, txRealtime, @@ -627,7 +627,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async * @spec RTL6 * @spec RTL6b */ - Helper.testOnAllTransports('publish', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'publish', function (realtimeOpts) { return function (done) { const helper = this.test.helper; var count = 10; diff --git a/test/realtime/reauth.test.js b/test/realtime/reauth.test.js index b08393515..0653bdc3e 100644 --- a/test/realtime/reauth.test.js +++ b/test/realtime/reauth.test.js @@ -177,8 +177,8 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { }; } - function testCase(name, createSteps) { - Helper.testOnAllTransports(name, function (realtimeOpts) { + function testCase(thisInDescribe, name, createSteps) { + Helper.testOnAllTransports(thisInDescribe, name, function (realtimeOpts) { return function (done) { const helper = this.test.helper; var _steps = createSteps(helper).slice(); @@ -203,7 +203,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { ****************/ /** @specpartial RTC8a1 - change capability without loss of continuity */ - testCase('reauthCapabilityUpgradeNewChannel', (helper) => [ + testCase(this, 'reauthCapabilityUpgradeNewChannel', (helper) => [ getToken(helper, { clientId: clientId, capability: { wrongchannel: ['*'] } }), connectWithToken(helper), monitorConnectionContinuity(helper), @@ -215,7 +215,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { ]); /** @specpartial RTC8a1 - capability downgrade leads to an error an failed channel state */ - testCase('reauthCapabilityDowngradeFullChannel', (helper) => [ + testCase(this, 'reauthCapabilityDowngradeFullChannel', (helper) => [ getToken(helper, { clientId: clientId, capability: { channel: ['*'], another: ['*'] } }), connectWithToken(helper), monitorConnectionContinuity(helper), @@ -232,7 +232,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * Related to RTC8a1. * @nospec */ - testCase('reauthCapabilityUpgradeAddPublish', (helper) => [ + testCase(this, 'reauthCapabilityUpgradeAddPublish', (helper) => [ getToken(helper, { clientId: clientId, capability: { channel: ['subscribe'] } }), connectWithToken(helper), monitorConnectionContinuity(helper), @@ -249,7 +249,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * Related to RTC8a1. * @nospec */ - testCase('reauthCapabilityDowngradePublish', (helper) => [ + testCase(this, 'reauthCapabilityDowngradePublish', (helper) => [ getToken(helper, { clientId: clientId, capability: { channel: ['subscribe', 'publish'] } }), connectWithToken(helper), monitorConnectionContinuity(helper), diff --git a/test/realtime/resume.test.js b/test/realtime/resume.test.js index d41af8e56..b49ebecc8 100644 --- a/test/realtime/resume.test.js +++ b/test/realtime/resume.test.js @@ -138,7 +138,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * Related to RTN15b, RTN15c. * @nospec */ - Helper.testOnAllTransports('resume_inactive', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'resume_inactive', function (realtimeOpts) { return function (done) { resume_inactive(done, this.test.helper, 'resume_inactive' + String(Math.random()), {}, realtimeOpts); }; @@ -262,7 +262,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * Related to RTN15b, RTN15c. * @nospec */ - Helper.testOnAllTransports('resume_active', function (realtimeOpts) { + Helper.testOnAllTransports(this, 'resume_active', function (realtimeOpts) { return function (done) { resume_active(done, this.test.helper, 'resume_active' + String(Math.random()), {}, realtimeOpts); }; @@ -273,6 +273,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * @spec RTN15c7 */ Helper.testOnAllTransports( + this, 'resume_lost_continuity', function (realtimeOpts) { return function (done) { @@ -341,6 +342,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * @spec RTN15c5 */ Helper.testOnAllTransports( + this, 'resume_token_error', function (realtimeOpts) { return function (done) { @@ -396,6 +398,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) { * @spec RTN15c4 */ Helper.testOnAllTransports( + this, 'resume_fatal_error', function (realtimeOpts) { return function (done) {