Skip to content

Commit d1d9e0f

Browse files
authored
chore: adds CompositeDataSource for FDv2 support (#787)
**Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [ ] I have validated my changes against all supported platform versions Will be done on target temp branch eventually. **Related issues** SDK-857
1 parent 5dbe832 commit d1d9e0f

File tree

13 files changed

+1035
-19
lines changed

13 files changed

+1035
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"test": "echo Please run tests for individual packages.",
4444
"coverage": "npm run test -- --coverage",
4545
"contract-test-service": "npm --prefix contract-tests install && npm --prefix contract-tests start",
46-
"contract-test-harness": "curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/master/downloader/run.sh \\ | VERSION=v2 PARAMS=\"-url http://localhost:8000 -debug -stop-service-at-end $TEST_HARNESS_PARAMS\" sh",
46+
"contract-test-harness": "curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/master/downloader/run.sh \\ | VERSION=v2 PARAMS=\"-url http://localhost:8000 -debug --skip-from=./contract-tests/testharness-suppressions.txt -stop-service-at-end $TEST_HARNESS_PARAMS\" sh",
4747
"contract-tests": "npm run contract-test-service & npm run contract-test-harness",
4848
"prettier": "npx prettier --write \"**/*.{js,ts,tsx,json,yaml,yml,md}\" --log-level warn",
4949
"check": "yarn && yarn prettier && yarn lint && tsc && yarn build"

packages/sdk/browser/src/platform/DefaultBrowserEventSource.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {
2+
DefaultBackoff,
23
EventListener,
34
EventName,
45
EventSourceInitDict,
56
HttpErrorResponse,
67
EventSource as LDEventSource,
78
} from '@launchdarkly/js-client-sdk-common';
89

9-
import Backoff from './Backoff';
10-
1110
/**
1211
* Implementation Notes:
1312
*
@@ -22,7 +21,7 @@ import Backoff from './Backoff';
2221
*/
2322
export default class DefaultBrowserEventSource implements LDEventSource {
2423
private _es?: EventSource;
25-
private _backoff: Backoff;
24+
private _backoff: DefaultBackoff;
2625
private _errorFilter: (err: HttpErrorResponse) => boolean;
2726

2827
// The type of the handle can be platform specific and we treat is opaquely.
@@ -34,7 +33,10 @@ export default class DefaultBrowserEventSource implements LDEventSource {
3433
private readonly _url: string,
3534
options: EventSourceInitDict,
3635
) {
37-
this._backoff = new Backoff(options.initialRetryDelayMillis, options.retryResetIntervalMillis);
36+
this._backoff = new DefaultBackoff(
37+
options.initialRetryDelayMillis,
38+
options.retryResetIntervalMillis,
39+
);
3840
this._errorFilter = options.errorFilter;
3941
this._openConnection();
4042
}

packages/sdk/browser/__tests__/platform/Backoff.test.ts renamed to packages/shared/common/__tests__/datasource/Backoff.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import Backoff from '../../src/platform/Backoff';
1+
import { DefaultBackoff } from '../../src/datasource/Backoff';
22

33
const noJitter = (): number => 0;
44
const maxJitter = (): number => 1;
55
const defaultResetInterval = 60 * 1000;
66

77
it.each([1, 1000, 5000])('has the correct starting delay', (initialDelay) => {
8-
const backoff = new Backoff(initialDelay, defaultResetInterval, noJitter);
8+
const backoff = new DefaultBackoff(initialDelay, defaultResetInterval, noJitter);
99
expect(backoff.fail()).toEqual(initialDelay);
1010
});
1111

1212
it.each([1, 1000, 5000])('doubles delay on consecutive failures', (initialDelay) => {
13-
const backoff = new Backoff(initialDelay, defaultResetInterval, noJitter);
13+
const backoff = new DefaultBackoff(initialDelay, defaultResetInterval, noJitter);
1414
expect(backoff.fail()).toEqual(initialDelay);
1515
expect(backoff.fail()).toEqual(initialDelay * 2);
1616
expect(backoff.fail()).toEqual(initialDelay * 4);
1717
});
1818

1919
it('stops increasing delay when the max backoff is encountered', () => {
20-
const backoff = new Backoff(5000, defaultResetInterval, noJitter);
20+
const backoff = new DefaultBackoff(5000, defaultResetInterval, noJitter);
2121
expect(backoff.fail()).toEqual(5000);
2222
expect(backoff.fail()).toEqual(10000);
2323
expect(backoff.fail()).toEqual(20000);
2424
expect(backoff.fail()).toEqual(30000);
2525

26-
const backoff2 = new Backoff(1000, defaultResetInterval, noJitter);
26+
const backoff2 = new DefaultBackoff(1000, defaultResetInterval, noJitter);
2727
expect(backoff2.fail()).toEqual(1000);
2828
expect(backoff2.fail()).toEqual(2000);
2929
expect(backoff2.fail()).toEqual(4000);
@@ -33,12 +33,12 @@ it('stops increasing delay when the max backoff is encountered', () => {
3333
});
3434

3535
it('handles an initial retry delay longer than the maximum retry delay', () => {
36-
const backoff = new Backoff(40000, defaultResetInterval, noJitter);
36+
const backoff = new DefaultBackoff(40000, defaultResetInterval, noJitter);
3737
expect(backoff.fail()).toEqual(30000);
3838
});
3939

4040
it('jitters the backoff value', () => {
41-
const backoff = new Backoff(1000, defaultResetInterval, maxJitter);
41+
const backoff = new DefaultBackoff(1000, defaultResetInterval, maxJitter);
4242
expect(backoff.fail()).toEqual(500);
4343
expect(backoff.fail()).toEqual(1000);
4444
expect(backoff.fail()).toEqual(2000);
@@ -51,7 +51,7 @@ it.each([10 * 1000, 60 * 1000])(
5151
'resets the delay when the last successful connection was connected greater than the retry reset interval',
5252
(retryResetInterval) => {
5353
let time = 1000;
54-
const backoff = new Backoff(1000, retryResetInterval, noJitter);
54+
const backoff = new DefaultBackoff(1000, retryResetInterval, noJitter);
5555
expect(backoff.fail(time)).toEqual(1000);
5656
time += 1;
5757
backoff.success(time);
@@ -69,7 +69,7 @@ it.each([10 * 1000, 60 * 1000])(
6969
it.each([10 * 1000, 60 * 1000])(
7070
'does not reset the delay when the connection did not persist longer than the retry reset interval',
7171
(retryResetInterval) => {
72-
const backoff = new Backoff(1000, retryResetInterval, noJitter);
72+
const backoff = new DefaultBackoff(1000, retryResetInterval, noJitter);
7373

7474
let time = 1000;
7575
expect(backoff.fail(time)).toEqual(1000);

0 commit comments

Comments
 (0)