Skip to content

Commit 0bf4291

Browse files
Move availableTransports and bestTransport inside helper
Preparation for recording private API usage by tests (ECO-4821).
1 parent 4f0dbbe commit 0bf4291

File tree

8 files changed

+55
-46
lines changed

8 files changed

+55
-46
lines changed

test/common/modules/shared_helper.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ define([
1515
var platform = clientModule.Ably.Realtime.Platform;
1616
var BufferUtils = platform.BufferUtils;
1717
var expect = chai.expect;
18-
var availableTransports = utils.keysArray(
19-
clientModule.Ably.Realtime.ConnectionManager.supportedTransports(clientModule.Ably.Realtime._transports),
20-
);
21-
var bestTransport = availableTransports[0];
2218
/* IANA reserved; requests to it will hang forever */
2319
var unroutableHost = '10.255.255.1';
2420
var unroutableAddress = 'http://' + unroutableHost + '/';
@@ -37,8 +33,6 @@ define([
3733
loadTestData = testAppManager.loadJsonData;
3834
testResourcesPath = testAppManager.testResourcesPath;
3935

40-
availableTransports = availableTransports;
41-
bestTransport = bestTransport;
4236
unroutableHost = unroutableHost;
4337
unroutableAddress = unroutableAddress;
4438
flushTestLogs = globals.flushLogs;
@@ -65,6 +59,16 @@ define([
6559
return new this(`${thisInDescribe.title} (defining ${label})`);
6660
}
6761

62+
get availableTransports() {
63+
return utils.keysArray(
64+
clientModule.Ably.Realtime.ConnectionManager.supportedTransports(clientModule.Ably.Realtime._transports),
65+
);
66+
}
67+
68+
get bestTransport() {
69+
return this.availableTransports[0];
70+
}
71+
6872
displayError(err) {
6973
if (typeof err == 'string' || err == null) return err;
7074

@@ -196,9 +200,10 @@ define([
196200
}
197201

198202
/* testFn is assumed to be a function of realtimeOptions that returns a mocha test */
199-
static testOnAllTransports(name, testFn, skip) {
203+
static testOnAllTransports(thisInDescribe, name, testFn, skip) {
204+
const helper = this.forTestDefinition(thisInDescribe, name);
200205
var itFn = skip ? it.skip : it;
201-
let transports = availableTransports;
206+
let transports = helper.availableTransports;
202207
transports.forEach(function (transport) {
203208
itFn(
204209
name + '_with_' + transport + '_binary_transport',
@@ -302,8 +307,8 @@ define([
302307
}
303308
}
304309

305-
SharedHelper.testOnAllTransports.skip = function (name, testFn) {
306-
SharedHelper.testOnAllTransports(name, testFn, true);
310+
SharedHelper.testOnAllTransports.skip = function (thisInDescribe, name, testFn) {
311+
SharedHelper.testOnAllTransports(thisInDescribe, name, testFn, true);
307312
};
308313

309314
SharedHelper.restTestOnJsonMsgpack.skip = function (name, testFn) {

test/realtime/auth.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
768768
* @spec RSA4b1
769769
* @specpartial RSA4b - token expired
770770
*/
771-
Helper.testOnAllTransports('auth_token_expires', function (realtimeOpts) {
771+
Helper.testOnAllTransports(this, 'auth_token_expires', function (realtimeOpts) {
772772
return function (done) {
773773
var helper = this.test.helper,
774774
clientRealtime,
@@ -871,7 +871,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
871871
* @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire
872872
* @specpartial RSA10e - obtain new token from authcallback when previous expires
873873
*/
874-
Helper.testOnAllTransports('auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) {
874+
Helper.testOnAllTransports(this, 'auth_tokenDetails_expiry_with_authcallback', function (realtimeOpts) {
875875
return function (done) {
876876
var helper = this.test.helper,
877877
realtime,
@@ -919,7 +919,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
919919
* @specpartial RTN15a - attempt to reconnect and restore the connection state on token expire
920920
* @specpartial RSA10e - obtain new token from authcallback when previous expires
921921
*/
922-
Helper.testOnAllTransports('auth_token_string_expiry_with_authcallback', function (realtimeOpts) {
922+
Helper.testOnAllTransports(this, 'auth_token_string_expiry_with_authcallback', function (realtimeOpts) {
923923
return function (done) {
924924
var helper = this.test.helper,
925925
realtime,
@@ -965,7 +965,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
965965
* @spec RSA4a
966966
* @spec RSA4a2
967967
*/
968-
Helper.testOnAllTransports('auth_token_string_expiry_with_token', function (realtimeOpts) {
968+
Helper.testOnAllTransports(this, 'auth_token_string_expiry_with_token', function (realtimeOpts) {
969969
return function (done) {
970970
var helper = this.test.helper,
971971
realtime,
@@ -1012,7 +1012,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
10121012
* @spec RSA4a
10131013
* @spec RSA4a2
10141014
*/
1015-
Helper.testOnAllTransports('auth_expired_token_string', function (realtimeOpts) {
1015+
Helper.testOnAllTransports(this, 'auth_expired_token_string', function (realtimeOpts) {
10161016
return function (done) {
10171017
var helper = this.test.helper,
10181018
realtime,
@@ -1061,7 +1061,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
10611061
* @spec RTC8
10621062
* @specskip
10631063
*/
1064-
Helper.testOnAllTransports.skip('reauth_authCallback', function (realtimeOpts) {
1064+
Helper.testOnAllTransports.skip(this, 'reauth_authCallback', function (realtimeOpts) {
10651065
return function (done) {
10661066
var helper = this.test.helper,
10671067
realtime,
@@ -1564,7 +1564,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
15641564
});
15651565

15661566
/** @nospec */
1567-
Helper.testOnAllTransports('authorize_immediately_after_init', function (realtimeOpts) {
1567+
Helper.testOnAllTransports(this, 'authorize_immediately_after_init', function (realtimeOpts) {
15681568
return function (done) {
15691569
const helper = this.test.helper;
15701570
var realtime = helper.AblyRealtime({

test/realtime/channel.test.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
170170
* @spec RTS3c
171171
* @spec RTL16
172172
*/
173-
Helper.testOnAllTransports('channelinit0', function (realtimeOpts) {
173+
Helper.testOnAllTransports(this, 'channelinit0', function (realtimeOpts) {
174174
return function (done) {
175175
const helper = this.test.helper;
176176
try {
@@ -207,7 +207,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
207207
*
208208
* @spec RTL4
209209
*/
210-
Helper.testOnAllTransports('channelattach0', function (realtimeOpts) {
210+
Helper.testOnAllTransports(this, 'channelattach0', function (realtimeOpts) {
211211
return function (done) {
212212
const helper = this.test.helper;
213213
try {
@@ -234,7 +234,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
234234
*
235235
* @spec RTL4
236236
*/
237-
Helper.testOnAllTransports('channelattach2', function (realtimeOpts) {
237+
Helper.testOnAllTransports(this, 'channelattach2', function (realtimeOpts) {
238238
return function (done) {
239239
const helper = this.test.helper;
240240
try {
@@ -262,6 +262,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
262262
* @spec RTL5
263263
*/
264264
Helper.testOnAllTransports(
265+
this,
265266
'channelattach3',
266267
function (realtimeOpts) {
267268
return function (done) {
@@ -301,7 +302,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
301302
*
302303
* @spec RTL4d
303304
*/
304-
Helper.testOnAllTransports('channelattachempty', function (realtimeOpts) {
305+
Helper.testOnAllTransports(this, 'channelattachempty', function (realtimeOpts) {
305306
return function (done) {
306307
const helper = this.test.helper;
307308
try {
@@ -336,7 +337,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
336337
*
337338
* @spec RTL4d
338339
*/
339-
Helper.testOnAllTransports('channelattachinvalid', function (realtimeOpts) {
340+
Helper.testOnAllTransports(this, 'channelattachinvalid', function (realtimeOpts) {
340341
return function (done) {
341342
const helper = this.test.helper;
342343
try {
@@ -377,7 +378,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
377378
*
378379
* @spec RTL6
379380
*/
380-
Helper.testOnAllTransports('publish_no_attach', function (realtimeOpts) {
381+
Helper.testOnAllTransports(this, 'publish_no_attach', function (realtimeOpts) {
381382
return function (done) {
382383
const helper = this.test.helper;
383384
try {
@@ -407,7 +408,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
407408
*
408409
* @specpartial RTL6b - callback which is called with an error
409410
*/
410-
Helper.testOnAllTransports('channelattach_publish_invalid', function (realtimeOpts) {
411+
Helper.testOnAllTransports(this, 'channelattach_publish_invalid', function (realtimeOpts) {
411412
return function (done) {
412413
const helper = this.test.helper;
413414
try {
@@ -441,7 +442,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
441442
*
442443
* @nospec
443444
*/
444-
Helper.testOnAllTransports('channelattach_invalid_twice', function (realtimeOpts) {
445+
Helper.testOnAllTransports(this, 'channelattach_invalid_twice', function (realtimeOpts) {
445446
return function (done) {
446447
const helper = this.test.helper;
447448
try {
@@ -536,7 +537,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
536537
* @spec RTL4k1
537538
* @spec RTL4m
538539
*/
539-
Helper.testOnAllTransports('attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) {
540+
Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicChannelsGet', function (realtimeOpts) {
540541
return function (done) {
541542
const helper = this.test.helper;
542543
var testName = 'attachWithChannelParamsBasicChannelsGet';
@@ -598,7 +599,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
598599
* @spec RTL4m
599600
* @spec RTL16
600601
*/
601-
Helper.testOnAllTransports('attachWithChannelParamsBasicSetOptions', function (realtimeOpts) {
602+
Helper.testOnAllTransports(this, 'attachWithChannelParamsBasicSetOptions', function (realtimeOpts) {
602603
return function (done) {
603604
const helper = this.test.helper;
604605
var testName = 'attachWithChannelParamsBasicSetOptions';
@@ -652,7 +653,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
652653
* @spec RTL16
653654
* @spec RTL7c
654655
*/
655-
Helper.testOnAllTransports('subscribeAfterSetOptions', function (realtimeOpts) {
656+
Helper.testOnAllTransports(this, 'subscribeAfterSetOptions', function (realtimeOpts) {
656657
return function (done) {
657658
const helper = this.test.helper;
658659
var testName = 'subscribeAfterSetOptions';
@@ -728,7 +729,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
728729
});
729730

730731
/** @spec RTL16a */
731-
Helper.testOnAllTransports('setOptionsCallbackBehaviour', function (realtimeOpts) {
732+
Helper.testOnAllTransports(this, 'setOptionsCallbackBehaviour', function (realtimeOpts) {
732733
return function (done) {
733734
const helper = this.test.helper;
734735
var testName = 'setOptionsCallbackBehaviour';
@@ -807,7 +808,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
807808
* Verify modes is ignored when params.modes is present
808809
* @nospec
809810
*/
810-
Helper.testOnAllTransports('attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) {
811+
Helper.testOnAllTransports(this, 'attachWithChannelParamsModesAndChannelModes', function (realtimeOpts) {
811812
return function (done) {
812813
const helper = this.test.helper;
813814
var testName = 'attachWithChannelParamsModesAndChannelModes';
@@ -869,7 +870,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
869870
* @spec RTL4l
870871
* @spec RTL4m
871872
*/
872-
Helper.testOnAllTransports('attachWithChannelModes', function (realtimeOpts) {
873+
Helper.testOnAllTransports(this, 'attachWithChannelModes', function (realtimeOpts) {
873874
return function (done) {
874875
const helper = this.test.helper;
875876
var testName = 'attachWithChannelModes';
@@ -928,7 +929,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
928929
* @spec RTL4l
929930
* @spec RTL4m
930931
*/
931-
Helper.testOnAllTransports('attachWithChannelParamsDeltaAndModes', function (realtimeOpts) {
932+
Helper.testOnAllTransports(this, 'attachWithChannelParamsDeltaAndModes', function (realtimeOpts) {
932933
return function (done) {
933934
const helper = this.test.helper;
934935
var testName = 'attachWithChannelParamsDeltaAndModes';

test/realtime/crypto.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,14 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
484484

485485
// Publish and subscribe, various transport, 128 and 256-bit
486486
/** @specpartial RSL5b - test aes 128 */
487-
Helper.testOnAllTransports('single_send_128', function (realtimeOpts) {
487+
Helper.testOnAllTransports(this, 'single_send_128', function (realtimeOpts) {
488488
return function (done) {
489489
single_send(done, this.test.helper, realtimeOpts, 128);
490490
};
491491
});
492492

493493
/** @specpartial RSL5b - test aes 256 */
494-
Helper.testOnAllTransports('single_send_256', function (realtimeOpts) {
494+
Helper.testOnAllTransports(this, 'single_send_256', function (realtimeOpts) {
495495
return function (done) {
496496
single_send(done, this.test.helper, realtimeOpts, 256);
497497
};

test/realtime/failure.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
603603
});
604604

605605
/** @specpartial RTN14d - last sentence: check that if we received a 5xx disconnected, when we try again we use a fallback host */
606-
Helper.testOnAllTransports('try_fallback_hosts_on_placement_constraint', function (realtimeOpts) {
606+
Helper.testOnAllTransports(this, 'try_fallback_hosts_on_placement_constraint', function (realtimeOpts) {
607607
return function (done) {
608608
/* Use the echoserver as a fallback host because it doesn't support
609609
* websockets, so it'll fail to connect, which we can detect */

test/realtime/message.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
7878
* Test publishes in quick succession (on successive ticks of the event loop)
7979
* @spec RTL6b
8080
*/
81-
Helper.testOnAllTransports('publishfast', function (realtimeOpts) {
81+
Helper.testOnAllTransports(this, 'publishfast', function (realtimeOpts) {
8282
return function (done) {
8383
const helper = this.test.helper;
8484
try {
@@ -145,7 +145,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
145145
* @spec RTL6c2
146146
* @specpartial RTL3d - test processing queued messages
147147
*/
148-
Helper.testOnAllTransports('publishQueued', function (realtimeOpts) {
148+
Helper.testOnAllTransports(this, 'publishQueued', function (realtimeOpts) {
149149
return function (done) {
150150
var helper = this.test.helper,
151151
txRealtime,
@@ -627,7 +627,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, Helper, async
627627
* @spec RTL6
628628
* @spec RTL6b
629629
*/
630-
Helper.testOnAllTransports('publish', function (realtimeOpts) {
630+
Helper.testOnAllTransports(this, 'publish', function (realtimeOpts) {
631631
return function (done) {
632632
const helper = this.test.helper;
633633
var count = 10;

test/realtime/reauth.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
177177
};
178178
}
179179

180-
function testCase(name, createSteps) {
181-
Helper.testOnAllTransports(name, function (realtimeOpts) {
180+
function testCase(thisInDescribe, name, createSteps) {
181+
Helper.testOnAllTransports(thisInDescribe, name, function (realtimeOpts) {
182182
return function (done) {
183183
const helper = this.test.helper;
184184
var _steps = createSteps(helper).slice();
@@ -203,7 +203,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
203203
****************/
204204

205205
/** @specpartial RTC8a1 - change capability without loss of continuity */
206-
testCase('reauthCapabilityUpgradeNewChannel', (helper) => [
206+
testCase(this, 'reauthCapabilityUpgradeNewChannel', (helper) => [
207207
getToken(helper, { clientId: clientId, capability: { wrongchannel: ['*'] } }),
208208
connectWithToken(helper),
209209
monitorConnectionContinuity(helper),
@@ -215,7 +215,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
215215
]);
216216

217217
/** @specpartial RTC8a1 - capability downgrade leads to an error an failed channel state */
218-
testCase('reauthCapabilityDowngradeFullChannel', (helper) => [
218+
testCase(this, 'reauthCapabilityDowngradeFullChannel', (helper) => [
219219
getToken(helper, { clientId: clientId, capability: { channel: ['*'], another: ['*'] } }),
220220
connectWithToken(helper),
221221
monitorConnectionContinuity(helper),
@@ -232,7 +232,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
232232
* Related to RTC8a1.
233233
* @nospec
234234
*/
235-
testCase('reauthCapabilityUpgradeAddPublish', (helper) => [
235+
testCase(this, 'reauthCapabilityUpgradeAddPublish', (helper) => [
236236
getToken(helper, { clientId: clientId, capability: { channel: ['subscribe'] } }),
237237
connectWithToken(helper),
238238
monitorConnectionContinuity(helper),
@@ -249,7 +249,7 @@ define(['shared_helper', 'async', 'chai'], function (Helper, async, chai) {
249249
* Related to RTC8a1.
250250
* @nospec
251251
*/
252-
testCase('reauthCapabilityDowngradePublish', (helper) => [
252+
testCase(this, 'reauthCapabilityDowngradePublish', (helper) => [
253253
getToken(helper, { clientId: clientId, capability: { channel: ['subscribe', 'publish'] } }),
254254
connectWithToken(helper),
255255
monitorConnectionContinuity(helper),

0 commit comments

Comments
 (0)