From be6a9ac2498953936c65df015b3fcd32b0e3231a Mon Sep 17 00:00:00 2001 From: Andrew Bulat Date: Fri, 5 Apr 2024 11:49:40 +0100 Subject: [PATCH] Add tests for TO3l6 --- test/realtime/init.test.js | 7 ++++++- test/rest/fallbacks.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/test/realtime/init.test.js b/test/realtime/init.test.js index bca2f44f8..f80fb64a5 100644 --- a/test/realtime/init.test.js +++ b/test/realtime/init.test.js @@ -238,6 +238,7 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { disconnectedRetryTimeout: 123, suspendedRetryTimeout: 456, httpRequestTimeout: 789, + httpMaxRetryDuration: 321, }); /* Note: uses internal knowledge of connectionManager */ try { @@ -251,7 +252,11 @@ define(['ably', 'shared_helper', 'chai'], function (Ably, helper, chai) { ); expect(realtime.connection.connectionManager.options.timeouts.httpRequestTimeout).to.equal( 789, - 'Verify suspended retry frequency is settable', + 'Verify http request timeout is settable', + ); + expect(realtime.connection.connectionManager.options.timeouts.httpMaxRetryDuration).to.equal( + 321, + 'Verify http max retry duration is settable', ); } catch (err) { closeAndFinish(done, realtime, err); diff --git a/test/rest/fallbacks.test.js b/test/rest/fallbacks.test.js index e0883def5..16b2d1253 100644 --- a/test/rest/fallbacks.test.js +++ b/test/rest/fallbacks.test.js @@ -50,5 +50,30 @@ define(['shared_helper', 'async', 'chai'], function (helper, async, chai) { expect(currentFallback && currentFallback.host).to.equal(goodHost, 'Check good host set again'); expect(currentFallback.validUntil > now, 'Check validUntil has been re-set').to.be.ok; }); + + // TO3l6 + it('Max elapsed time for fallback host retries', async function () { + // set httpMaxRetryDuration lower than httpRequestTimeout so it would fail after first host retry + const httpMaxRetryDuration = 1000; + const rest = helper.AblyRest({ + restHost: helper.unroutableHost, + fallbackHosts: [helper.unroutableHost], + httpRequestTimeout: 2000, + httpMaxRetryDuration, + }); + + let thrownError = null; + try { + // we expect it to fail due to max elapsed time reached for fallback host retries + await rest.time(); + } catch (error) { + thrownError = error; + } + + expect(thrownError).not.to.be.null; + expect(thrownError.message).to.equal( + `Timeout for trying fallback hosts retries. Total elapsed time exceeded the ${httpMaxRetryDuration}ms limit`, + ); + }); }); });