Skip to content

Commit

Permalink
further
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-forooghian committed Jun 5, 2024
1 parent cb893b8 commit 138a65f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
6 changes: 3 additions & 3 deletions docs/internal/private-api-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);`
Expand All @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions test/common/modules/private_api_recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
68 changes: 45 additions & 23 deletions test/realtime/connectivity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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');
Expand Down

0 comments on commit 138a65f

Please sign in to comment.