From 138a65ff0ee4eacd898cbca9798a28b9270714b5 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 5 Jun 2024 16:33:13 -0300 Subject: [PATCH] further --- docs/internal/private-api-usage.md | 6 +- test/common/modules/private_api_recorder.js | 3 + test/realtime/connectivity.test.js | 68 ++++++++++++++------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/docs/internal/private-api-usage.md b/docs/internal/private-api-usage.md index 305b46a3a..9b84e2361 100644 --- a/docs/internal/private-api-usage.md +++ b/docs/internal/private-api-usage.md @@ -179,7 +179,7 @@ Marked in code. ### `test/realtime/init.test.js` -Marked in tests. +Marked in code. - accesses `var transport = realtime.connection.connectionManager.activeProtocol.transport.uri` or `.recvRequest.recvUri` to check the `v=3` query parameter - `expect(realtime.options).to.deep.equal(realtime.connection.connectionManager.options);` @@ -193,12 +193,12 @@ Marked in tests. ### `test/realtime/history.test.js` -Marked in code (there’s actually a usage of `Utils.inspectError`). - None ### `test/realtime/connectivity.test.js` +Marked in code. + - directly calls `new Ably.Realtime._Http().checkConnectivity()` and checks it succeeds (i.e. directly tests this method) ### `test/realtime/reauth.test.js` diff --git a/test/common/modules/private_api_recorder.js b/test/common/modules/private_api_recorder.js index 663de3a07..718c2fea6 100644 --- a/test/common/modules/private_api_recorder.js +++ b/test/common/modules/private_api_recorder.js @@ -29,6 +29,7 @@ define([], function () { 'call.filteredSubscriptions.has', 'call.http._getHosts', 'call.http.doUri', + 'call.http.checkConnectivity', 'call.msgpack.decode', 'call.msgpack.encode', 'call.presence._myMembers.put', @@ -44,6 +45,8 @@ define([], function () { 'listen.connectionManager.transport.active', 'listen.connectionManager.transport.pending', 'pass.clientOption.webSocketConnectTimeout', + 'pass.clientOption.connectivityCheckUrl', // actually ably-js public API but no other SDK has it and it doesn’t enable ably-js-specific functionality + 'pass.clientOption.disableConnectivityCheck', // actually ably-js public API but no other SDK has it and it doesn’t enable ably-js-specific functionality 'read.Defaults.protocolVersion', 'read.EventEmitter.events', 'read.auth.authOptions.authUrl', diff --git a/test/realtime/connectivity.test.js b/test/realtime/connectivity.test.js index b6a3546d4..857ceec50 100644 --- a/test/realtime/connectivity.test.js +++ b/test/realtime/connectivity.test.js @@ -25,6 +25,7 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably it('http_connectivity_check', function (done) { const privateApiContext = privateApiRecorder.createContext(this); + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles(new Ably.Realtime._Http().checkConnectivity(), function (err, res) { try { privateApiContext.record('call.Utils.inspectError'); @@ -37,7 +38,9 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably }); }); - function options(connectivityCheckUrl, disableConnectivityCheck) { + function options(privateApiContext, connectivityCheckUrl, disableConnectivityCheck) { + privateApiContext.record('pass.clientOption.connectivityCheckUrl'); + privateApiContext.record('pass.clientOption.disableConnectivityCheck'); return { connectivityCheckUrl, disableConnectivityCheck, @@ -54,8 +57,9 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably it('succeeds with scheme', function (done) { const privateApiContext = privateApiRecorder.createContext(this); + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles( - new helper.AblyRealtime(options(urlScheme + successUrl)).http.checkConnectivity(), + new helper.AblyRealtime(options(privateApiContext, urlScheme + successUrl)).http.checkConnectivity(), function (err, res) { try { privateApiContext.record('call.Utils.inspectError'); @@ -70,8 +74,11 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably }); it('fails with scheme', function (done) { + const privateApiContext = privateApiRecorder.createContext(this); + + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles( - new helper.AblyRealtime(options(urlScheme + failUrl)).http.checkConnectivity(), + new helper.AblyRealtime(options(privateApiContext, urlScheme + failUrl)).http.checkConnectivity(), function (err, res) { try { expect(!res, 'Connectivity check expected to return false').to.be.ok; @@ -86,33 +93,44 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably it('succeeds with querystring', function (done) { const privateApiContext = privateApiRecorder.createContext(this); - whenPromiseSettles(new helper.AblyRealtime(options(successUrl)).http.checkConnectivity(), function (err, res) { - try { - privateApiContext.record('call.Utils.inspectError'); - expect(res && !err, 'Connectivity check completed ' + (err && utils.inspectError(err))).to.be.ok; - done(); - } catch (err) { - done(err); - } - }); + privateApiContext.record('call.http.checkConnectivity'); + whenPromiseSettles( + new helper.AblyRealtime(options(privateApiContext, successUrl)).http.checkConnectivity(), + function (err, res) { + try { + privateApiContext.record('call.Utils.inspectError'); + expect(res && !err, 'Connectivity check completed ' + (err && utils.inspectError(err))).to.be.ok; + done(); + } catch (err) { + done(err); + } + }, + ); }); it('fails with querystring', function (done) { - whenPromiseSettles(new helper.AblyRealtime(options(failUrl)).http.checkConnectivity(), function (err, res) { - try { - expect(!res, 'Connectivity check expected to return false').to.be.ok; - done(); - } catch (err) { - done(err); - } - }); + const privateApiContext = privateApiRecorder.createContext(this); + + privateApiContext.record('call.http.checkConnectivity'); + whenPromiseSettles( + new helper.AblyRealtime(options(privateApiContext, failUrl)).http.checkConnectivity(), + function (err, res) { + try { + expect(!res, 'Connectivity check expected to return false').to.be.ok; + done(); + } catch (err) { + done(err); + } + }, + ); }); it('succeeds with plain url', function (done) { const privateApiContext = privateApiRecorder.createContext(this); + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles( - new helper.AblyRealtime(options('sandbox-rest.ably.io/time')).http.checkConnectivity(), + new helper.AblyRealtime(options(privateApiContext, 'sandbox-rest.ably.io/time')).http.checkConnectivity(), function (err, res) { try { privateApiContext.record('call.Utils.inspectError'); @@ -126,8 +144,11 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably }); it('fails with plain url', function (done) { + const privateApiContext = privateApiRecorder.createContext(this); + + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles( - new helper.AblyRealtime(options('echo.ably.io')).http.checkConnectivity(), + new helper.AblyRealtime(options(privateApiContext, 'echo.ably.io')).http.checkConnectivity(), function (err, res) { try { expect(!res, 'Connectivity check expected to return false').to.be.ok; @@ -143,8 +164,9 @@ define(['ably', 'shared_helper', 'chai', 'private_api_recorder'], function (Ably it('disable_connectivity_check', function (done) { const privateApiContext = privateApiRecorder.createContext(this); + privateApiContext.record('call.http.checkConnectivity'); whenPromiseSettles( - new helper.AblyRealtime(options('notarealhost', true)).http.checkConnectivity(), + new helper.AblyRealtime(options(privateApiContext, 'notarealhost', true)).http.checkConnectivity(), function (err, res) { try { privateApiContext.record('call.Utils.inspectError');