8000 Merge branch 'master' into junaed/fssdk-11515-changelog-update · optimizely/javascript-sdk@8d60f38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d60f38

Browse files
Merge branch 'master' into junaed/fssdk-11515-changelog-update
2 parents eef1dc9 + a59bd3b commit 8d60f38

6 files changed

+18
-87
lines changed

lib/event_processor/batch_event_processor.spec.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2024, Optimizely
2+
* Copyright 2024-2025, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -639,53 +639,6 @@ describe('BatchEventProcessor', async () => {
639639
}
640640
});
641641

642-
it('should retry indefinitely using the provided backoffController if maxRetry is undefined', async () => {
643-
const eventDispatcher = getMockDispatcher();
644-
const mockDispatch: MockInstance<typeof eventDispatcher.dispatchEvent> = eventDispatcher.dispatchEvent;
645-
mockDispatch.mockRejectedValue(new Error());
646-
const dispatchRepeater = getMockRepeater();
647-
648-
const backoffController = {
649-
backoff: vi.fn().mockReturnValue(1000),
650-
reset: vi.fn(),
651-
};
652-
653-
const processor = new BatchEventProcessor({
654-
eventDispatcher,
655-
dispatchRepeater,
656-
retryConfig: {
657-
backoffProvider: () => backoffController,
658-
},
659-
batchSize: 100,
660-
});
661-
662-
processor.start();
663-
await processor.onRunning();
664-
665-
const events: ProcessableEvent[] = [];
666-
for(let i = 0; i < 10; i++) {
667-
const event = createImpressionEvent(`id-${i}`);
668-
events.push(event);
669-
await processor.process(event);
670-
}
671-
672-
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(0);
673-
await dispatchRepeater.execute(0);
674-
675-
for(let i = 0; i < 200; i++) {
676-
await exhaustMicrotasks();
677-
await advanceTimersByTime(1000);
678-
}
679-
680-
expect(eventDispatcher.dispatchEvent).toHaveBeenCalledTimes(201);
681-
expect(backoffController.backoff).toHaveBeenCalledTimes(200);
682-
683-
const request = buildLogEvent(events);
684-
for(let i = 0; i < 201; i++) {
685-
expect(eventDispatcher.dispatchEvent.mock.calls[i][0]).toEqual(request);
686-
}
687-
});
688-
689642
it('should remove the events from the eventStore after dispatch is successfull', async () => {
690643
const eventDispatcher = getMockDispatcher();
691644
const mockDispatch: MockInstance<typeof eventDispatcher.dispatchEvent> = eventDispatcher.dispatchEvent;

< 6D47 code>‎lib/event_processor/batch_event_processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type EventWithId = {
4444
};
4545

4646
export type RetryConfig = {
47-
maxRetries?: number;
47+
maxRetries: number;
4848
backoffProvider: Producer<BackoffController>;
4949
}
5050

lib/event_processor/event_processor_factory.node.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ describe('createBatchEventProcessor', () => {
187187
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
188188
});
189189

190-
it('uses maxRetries value of 10', () => {
190+
it('uses maxRetries value of 5', () => {
191191
const processor = createBatchEventProcessor({ });
192192
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
193-
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(10);
193+
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
194194
});
195195

196196
it('uses no failed event retry if an eventStore is not provided', () => {

lib/event_processor/event_processor_factory.node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const createBatchEventProcessor = (
4747
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
4848
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
4949
retryOptions: {
50-
maxRetries: 10,
50+
maxRetries: 5,
51+
5152
},
5253
failedEventRetryInterval: eventStore ? FAILED_EVENT_RETRY_INTERVAL : undefined,
5354
eventStore,

lib/event_processor/event_processor_factory.spec.ts

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2024, Optimizely
2+
* Copyright 2024-2025, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,24 +83,8 @@ describe('getBatchEventProcessor', () => {
8383
expect(MockBatchEventProcessor.mock.calls[0][0].retryConfig).toBe(undefined);
8484
});
8585

86-
it('uses retry when retryOptions is provided', () => {
87-
const options = {
88-
eventDispatcher: getMockEventDispatcher(),
89-
retryOptions: {},
90-
defaultFlushInterval: 1000,
91-
defaultBatchSize: 10,
92-
};
93-
94-
const processor = getBatchEventProcessor(options);
95-
96-
expect(Object.is(processor, MockBatchEventProcessor.mock.instances[0])).toBe(true);
97-
const usedRetryConfig = MockBatchEventProcessor.mock.calls[0][0].retryConfig;
98-
expect(usedRetryConfig).not.toBe(undefined);
99-
expect(usedRetryConfig?.backoffProvider).not.toBe(undefined);
100-
});
101-
10286
it('uses the correct maxRetries value when retryOptions is provided', () => {
103-
const options1 = {
87+
const options = {
10488
eventDispatcher: getMockEventDispatcher(),
10589
defaultFlushInterval: 1000,
10690
defaultBatchSize: 10,
@@ -109,34 +93,24 @@ describe('getBatchEventProcessor', () => {
10993
},
11094
};
11195

112-
const processor1 = getBatchEventProcessor(options1);
113-
expect(Object.is(processor1, MockBatchEventProcessor.mock.instances[0])).toBe(true);
96+
const processor = getBatchEventProcessor(options);
97+
expect(Object.is(processor, MockBatchEventProcessor.mock.instances[0])).toBe(true);
11498
expect(MockBatchEventProcessor.mock.calls[0][0].retryConfig?.maxRetries).toBe(10);
115-
116-
const options2 = {
117-
eventDispatcher: getMockEventDispatcher(),
118-
defaultFlushInterval: 1000,
119-
defaultBatchSize: 10,
120-
retryOptions: {},
121-
};
122-
123-
const processor2 = getBatchEventProcessor(options2);
124-
expect(Object.is(processor2, MockBatchEventProcessor.mock.instances[1])).toBe(true);
125-
expect(MockBatchEventProcessor.mock.calls[0][0].retryConfig).not.toBe(undefined);
126-
expect(MockBatchEventProcessor.mock.calls[1][0].retryConfig?.maxRetries).toBe(undefined);
12799
});
128100

129101
it('uses exponential backoff with default parameters when retryOptions is provided without backoff values', () => {
130102
const options = {
131103
eventDispatcher: getMockEventDispatcher(),
132104
defaultFlushInterval: 1000,
133105
defaultBatchSize: 10,
134-
retryOptions: {},
106+
retryOptions: { maxRetries: 2 },
135107
};
136108

137109
const processor = getBatchEventProcessor(options);
138110
expect(Object.is(processor, MockBatchEventProcessor.mock.instances[0])).toBe(true);
139111

112+
expect(MockBatchEventProcessor.mock.calls[0][0].retryConfig?.maxRetries).toBe(2);
113+
140114
const backoffProvider = MockBatchEventProcessor.mock.calls[0][0].retryConfig?.backoffProvider;
141115
expect(backoffProvider).not.toBe(undefined);
142116
const backoff = backoffProvider?.();
@@ -149,11 +123,14 @@ describe('getBatchEventProcessor', () => {
149123
eventDispatcher: getMockEventDispatcher(),
150124
defaultFlushInterval: 1000,
151125
defaultBatchSize: 10,
152-
retryOptions: { minBackoff: 1000, maxBackoff: 2000 },
126+
retryOptions: { maxRetries: C50E 2, minBackoff: 1000, maxBackoff: 2000 },
153127
};
154128

155129
const processor = getBatchEventProcessor(options);
156130
expect(Object.is(processor, MockBatchEventProcessor.mock.instances[0])).toBe(true);
131+
132+
expect(MockBatchEventProcessor.mock.calls[0][0].retryConfig?.maxRetries).toBe(2);
133+
157134
const backoffProvider = MockBatchEventProcessor.mock.calls[0][0].retryConfig?.backoffProvider;
158135

159136
expect(backoffProvider).not.toBe(undefined);

lib/event_processor/event_processor_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export type BatchEventProcessorFactoryOptions = Omit<BatchEventProcessorOptions,
6666
defaultBatchSize: number;
6767
eventStore?: Store<EventWithId>;
6868
retryOptions?: {
69-
maxRetries?: number;
69+
maxRetries: number;
7070
minBackoff?: number;
7171
maxBackoff?: number;
7272
};

0 commit comments

Comments
 (0)
0