Skip to content

Commit

Permalink
Move availableTransports and bestTransport inside helper
Browse files Browse the repository at this point in the history
Preparation for recording private API usage by tests (ECO-4821).
  • Loading branch information
lawrence-forooghian committed Jul 24, 2024
1 parent 4f0dbbe commit 0bf4291
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 46 deletions.
25 changes: 15 additions & 10 deletions test/common/modules/shared_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '/';
Expand All @@ -37,8 +33,6 @@ define([
loadTestData = testAppManager.loadJsonData;
testResourcesPath = testAppManager.testResourcesPath;

availableTransports = availableTransports;
bestTransport = bestTransport;
unroutableHost = unroutableHost;
unroutableAddress = unroutableAddress;
flushTestLogs = globals.flushLogs;
Expand All @@ -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;

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions test/realtime/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
31 changes: 16 additions & 15 deletions test/realtime/channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/realtime/crypto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion test/realtime/failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions test/realtime/message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions test/realtime/reauth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
Loading

0 comments on commit 0bf4291

Please sign in to comment.