Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/event_processor/event_processor_factory.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,22 @@ describe('createBatchEventProcessor', () => {
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
});

it('uses maxRetries value of 5', () => {
it('uses maxRetries value of 5 by default', () => {
const processor = createBatchEventProcessor({ });
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
});

it('uses the provided maxRetries value', () => {
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);

const processor2 = createBatchEventProcessor({ maxRetries: 10 });
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
});

it('uses the default failedEventRetryInterval', () => {
const processor = createBatchEventProcessor({ });
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
Expand Down
5 changes: 3 additions & 2 deletions lib/event_processor/event_processor_factory.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { DEFAULT_MAX_EVENTS_IN_STORE, EventStore } from './event_store';

export const DEFAULT_EVENT_BATCH_SIZE = 10;
export const DEFAULT_EVENT_FLUSH_INTERVAL = 1_000;
export const EVENT_MAX_RETRIES_BROWSER = 5;

export const createForwardingEventProcessor = (
eventDispatcher: EventDispatcher = defaultEventDispatcher,
Expand All @@ -51,14 +52,14 @@ export const createBatchEventProcessor = (

return getOpaqueBatchEventProcessor({
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
closingEventDispatcher: options.closingEventDispatcher ||
closingEventDispatcher: options.closingEventDispatcher ||
(options.eventDispatcher ? undefined : sendBeaconEventDispatcher),
flushInterval: options.flushInterval,
batchSize: options.batchSize,
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
retryOptions: {
maxRetries: 5,
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_BROWSER,
},
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
eventStore,
Expand Down
12 changes: 11 additions & 1 deletion lib/event_processor/event_processor_factory.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,22 @@ describe('createBatchEventProcessor', () => {
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
});

it('uses maxRetries value of 5', () => {
it('uses maxRetries value of 5 by default', () => {
const processor = createBatchEventProcessor({ });
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
});

it('uses the provided maxRetries value', () => {
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);

const processor2 = createBatchEventProcessor({ maxRetries: 10 });
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
});

it('uses no failed event retry if an eventStore is not provided', () => {
const processor = createBatchEventProcessor({ });
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
Expand Down
7 changes: 4 additions & 3 deletions lib/event_processor/event_processor_factory.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {

export const DEFAULT_EVENT_BATCH_SIZE = 10;
export const DEFAULT_EVENT_FLUSH_INTERVAL = 30_000;
export const EVENT_MAX_RETRIES_NODE = 5;

export const createForwardingEventProcessor = (
eventDispatcher: EventDispatcher = defaultEventDispatcher,
Expand All @@ -38,7 +39,7 @@ export const createBatchEventProcessor = (
options: BatchEventProcessorOptions = {}
): OpaqueEventProcessor => {
const eventStore = options.eventStore ? getPrefixEventStore(options.eventStore) : undefined;

return getOpaqueBatchEventProcessor({
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
closingEventDispatcher: options.closingEventDispatcher,
Expand All @@ -47,8 +48,8 @@ export const createBatchEventProcessor = (
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
retryOptions: {
maxRetries: 5,
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_NODE,

},
failedEventRetryInterval: eventStore ? FAILED_EVENT_RETRY_INTERVAL : undefined,
eventStore,
Expand Down
12 changes: 11 additions & 1 deletion lib/event_processor/event_processor_factory.react_native.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,22 @@ describe('createBatchEventProcessor', () => {
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].batchSize).toBe(undefined);
});

it('uses maxRetries value of 5', () => {
it('uses maxRetries value of 5 by default', () => {
const processor = createBatchEventProcessor({});
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(5);
});

it('uses the provided maxRetries value', () => {
const processor1 = createBatchEventProcessor({ maxRetries: 3 });
expect(Object.is(processor1, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[0][0].retryOptions?.maxRetries).toBe(3);

const processor2 = createBatchEventProcessor({ maxRetries: 10 });
expect(Object.is(processor2, mockGetOpaqueBatchEventProcessor.mock.results[1].value)).toBe(true);
expect(mockGetOpaqueBatchEventProcessor.mock.calls[1][0].retryOptions?.maxRetries).toBe(10);
});

it('uses the default failedEventRetryInterval', () => {
const processor = createBatchEventProcessor({});
expect(Object.is(processor, mockGetOpaqueBatchEventProcessor.mock.results[0].value)).toBe(true);
Expand Down
5 changes: 3 additions & 2 deletions lib/event_processor/event_processor_factory.react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DEFAULT_MAX_EVENTS_IN_STORE, EventStore } from './event_store';

export const DEFAULT_EVENT_BATCH_SIZE = 10;
export const DEFAULT_EVENT_FLUSH_INTERVAL = 1_000;
export const EVENT_MAX_RETRIES_REACT_NATIVE = 5;

export const createForwardingEventProcessor = (
eventDispatcher: EventDispatcher = defaultEventDispatcher,
Expand All @@ -47,7 +48,7 @@ export const createBatchEventProcessor = (
: DEFAULT_MAX_EVENTS_IN_STORE,
ttl: options.storeTtl,
});

return getOpaqueBatchEventProcessor(
{
eventDispatcher: options.eventDispatcher || defaultEventDispatcher,
Expand All @@ -57,7 +58,7 @@ export const createBatchEventProcessor = (
defaultFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
defaultBatchSize: DEFAULT_EVENT_BATCH_SIZE,
retryOptions: {
maxRetries: 5,
maxRetries: options.maxRetries ?? EVENT_MAX_RETRIES_REACT_NATIVE,
},
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
eventStore,
Expand Down
1 change: 1 addition & 0 deletions lib/event_processor/event_processor_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type BatchEventProcessorOptions = {
batchSize?: number;
storeTtl?: number;
eventStore?: Store<string>;
maxRetries?: number;
};

export type BatchEventProcessorFactoryOptions = Omit<BatchEventProcessorOptions, 'eventDispatcher' | 'eventStore' > & {
Expand Down
Loading