Skip to content

Commit

Permalink
Move availableTransports and bestTransport inside helper
Browse files Browse the repository at this point in the history
Preparation for logging private API usage.
  • Loading branch information
lawrence-forooghian committed Jun 12, 2024
1 parent 3a10b09 commit 72aebdf
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 @@ -655,7 +655,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Check state change reason is propogated during a disconnect
* (when connecting with a token that expires while connected)
*/
Helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'auth_token_expires', function (realtimeOpts) {
return function (done) {
var helper = this.helper,
clientRealtime,
Expand Down Expand Up @@ -751,7 +751,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* If using authcallback when a token expires, should automatically request a
* new token
*/
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.helper,
realtime,
Expand Down Expand Up @@ -795,7 +795,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Same as previous but with just a token, so ably-js doesn't know that the
* token's expired
*/
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.helper,
realtime,
Expand Down Expand Up @@ -838,7 +838,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Same as previous but with no way to generate a new token
*/
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.helper,
realtime,
Expand Down Expand Up @@ -882,7 +882,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Try to connect with an expired token string
*/
Helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'auth_expired_token_string', function (realtimeOpts) {
return function (done) {
var helper = this.helper,
realtime,
Expand Down Expand Up @@ -927,7 +927,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* use authorize() to force a reauth using an existing authCallback
*/
Helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) {
Helper.testOnAllTransports.skip(this, 'reauth_authCallback', function (realtimeOpts) {
return function (done) {
var helper = this.helper,
realtime,
Expand Down Expand Up @@ -1404,7 +1404,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
});
});

Helper.testOnAllTransports('authorize_immediately_after_init', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'authorize_immediately_after_init', function (realtimeOpts) {
return function (done) {
const helper = this.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 @@ -165,7 +165,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Channel init with options
*/
Helper.testOnAllTransports('channelinit0', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelinit0', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -199,7 +199,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Base attach case
*/
Helper.testOnAllTransports('channelattach0', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattach0', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand All @@ -223,7 +223,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Attach before connect
*/
Helper.testOnAllTransports('channelattach2', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattach2', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand All @@ -247,6 +247,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Attach then detach
*/
Helper.testOnAllTransports(
this,
'channelattach3',
function (realtimeOpts) {
return function (done) {
Expand Down Expand Up @@ -284,7 +285,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Attach with an empty channel and expect a channel error
* and the connection to remain open
*/
Helper.testOnAllTransports('channelattachempty', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattachempty', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -317,7 +318,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Attach with an invalid channel name and expect a channel error
* and the connection to remain open
*/
Helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattachinvalid', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -356,7 +357,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Publishing on a nonattached channel
*/
Helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'publish_no_attach', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -384,7 +385,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* publishing on a nonattached channel with an invalid channel name
*/
Helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattach_publish_invalid', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -414,7 +415,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Attach with an invalid channel name and expect a channel error
* and the connection to remain open
*/
Helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'channelattach_invalid_twice', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -496,7 +497,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
}
});

Helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'attachWithChannelParamsBasicChannelsGet';
Expand Down Expand Up @@ -550,7 +551,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
};
});

Helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicSetOptions', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'attachWithChannelParamsBasicSetOptions';
Expand Down Expand Up @@ -600,7 +601,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
};
});

Helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'subscribeAfterSetOptions', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'subscribeAfterSetOptions';
Expand Down Expand Up @@ -674,7 +675,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
}
});

Helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'setOptionsCallbackBehaviour', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'setOptionsCallbackBehaviour';
Expand Down Expand Up @@ -750,7 +751,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
});

/* Verify modes is ignored when params.modes is present */
Helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'attachWithChannelParamsModesAndChannelModes';
Expand Down Expand Up @@ -805,7 +806,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
};
});

Helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'attachWithChannelModes', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
var testName = 'attachWithChannelModes';
Expand Down Expand Up @@ -855,7 +856,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
};
});

Helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'attachWithChannelParamsDeltaAndModes', function (realtimeOpts) {
return function (done) {
const helper = this.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 @@ -430,13 +430,13 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/**
* Publish and subscribe, various transport, 128 and 256-bit
*/
Helper.testOnAllTransports('single_send_128', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'single_send_128', function (realtimeOpts) {
return function (done) {
single_send(done, this.helper, realtimeOpts, 128);
};
});

Helper.testOnAllTransports('single_send_256', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'single_send_256', function (realtimeOpts) {
return function (done) {
single_send(done, this.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 @@ -567,7 +567,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async

/* 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 @@ -73,7 +73,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
/*
* Test publishes in quick succession (on successive ticks of the event loop)
*/
Helper.testOnAllTransports('publishfast', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'publishfast', function (realtimeOpts) {
return function (done) {
const helper = this.helper;
try {
Expand Down Expand Up @@ -137,7 +137,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
* Test queuing: publishing a series of messages that start before the lib is connected
* Also checks they arrive in the right order
*/
Helper.testOnAllTransports('publishQueued', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'publishQueued', function (realtimeOpts) {
return function (done) {
var helper = this.helper,
txRealtime,
Expand Down Expand Up @@ -594,7 +594,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
}, 500);
});

Helper.testOnAllTransports('publish', function (realtimeOpts) {
Helper.testOnAllTransports(this, 'publish', function (realtimeOpts) {
return function (done) {
const helper = this.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.helper;
var _steps = createSteps(helper).slice();
Expand All @@ -203,7 +203,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
****************/

/* RTC8a1 */
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) {
]);

/* RTC8a1 */
testCase('reauthCapabilityDowngradeFullChannel', (helper) => [
testCase(this, 'reauthCapabilityDowngradeFullChannel', (helper) => [
getToken(helper, { clientId: clientId, capability: { channel: ['*'], another: ['*'] } }),
connectWithToken(helper),
monitorConnectionContinuity(helper),
Expand All @@ -228,7 +228,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
close(),
]);

testCase('reauthCapabilityUpgradeAddPublish', (helper) => [
testCase(this, 'reauthCapabilityUpgradeAddPublish', (helper) => [
getToken(helper, { clientId: clientId, capability: { channel: ['subscribe'] } }),
connectWithToken(helper),
monitorConnectionContinuity(helper),
Expand All @@ -241,7 +241,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
close(),
]);

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 72aebdf

Please sign in to comment.