15
15
*/
16
16
17
17
import { describe , it , expect , beforeEach , vi , MockInstance } from 'vitest' ;
18
- import { DEFAULT_EVENT_BATCH_SIZE , DEFAULT_EVENT_FLUSH_INTERVAL , getBatchEventProcessor } from './event_processor_factory' ;
18
+ import { getBatchEventProcessor } from './event_processor_factory' ;
19
19
import { BatchEventProcessor , BatchEventProcessorConfig , EventWithId , DEFAULT_MAX_BACKOFF , DEFAULT_MIN_BACKOFF } from './batch_event_processor' ;
20
20
import { ExponentialBackoff , IntervalRepeater } from '../utils/repeater/repeater' ;
21
21
import { getMockSyncCache } from '../tests/mock/mock_cache' ;
@@ -44,6 +44,8 @@ describe('getBatchEventProcessor', () => {
44
44
it ( 'returns an instane of BatchEventProcessor if no subclass constructor is provided' , ( ) => {
45
45
const options = {
46
46
eventDispatcher : getMockEventDispatcher ( ) ,
47
+ defaultFlushInterval : 1000 ,
48
+ defaultBatchSize : 10 ,
47
49
} ;
48
50
49
51
const processor = getBatchEventProcessor ( options ) ;
@@ -60,6 +62,8 @@ describe('getBatchEventProcessor', () => {
60
62
61
63
const options = {
62
64
eventDispatcher : getMockEventDispatcher ( ) ,
65
+ defaultFlushInterval : 1000 ,
66
+ defaultBatchSize : 10 ,
63
67
} ;
64
68
65
69
const processor = getBatchEventProcessor ( options , CustomEventProcessor ) ;
@@ -70,6 +74,8 @@ describe('getBatchEventProcessor', () => {
70
74
it ( 'does not use retry if retryOptions is not provided' , ( ) => {
71
75
const options = {
72
76
eventDispatcher : getMockEventDispatcher ( ) ,
77
+ defaultFlushInterval : 1000 ,
78
+ defaultBatchSize : 10 ,
73
79
} ;
74
80
75
81
const processor = getBatchEventProcessor ( options ) ;
@@ -81,6 +87,8 @@ describe('getBatchEventProcessor', () => {
81
87
const options = {
82
88
eventDispatcher : getMockEventDispatcher ( ) ,
83
89
retryOptions : { } ,
90
+ defaultFlushInterval : 1000 ,
91
+ defaultBatchSize : 10 ,
84
92
} ;
85
93
86
94
const processor = getBatchEventProcessor ( options ) ;
@@ -94,6 +102,8 @@ describe('getBatchEventProcessor', () => {
94
102
it ( 'uses the correct maxRetries value when retryOptions is provided' , ( ) => {
95
103
const options1 = {
96
104
eventDispatcher : getMockEventDispatcher ( ) ,
105
+ defaultFlushInterval : 1000 ,
106
+ defaultBatchSize : 10 ,
97
107
retryOptions : {
98
108
maxRetries : 10 ,
99
109
} ,
@@ -105,6 +115,8 @@ describe('getBatchEventProcessor', () => {
105
115
106
116
const options2 = {
107
117
eventDispatcher : getMockEventDispatcher ( ) ,
118
+ defaultFlushInterval : 1000 ,
119
+ defaultBatchSize : 10 ,
108
120
retryOptions : { } ,
109
121
} ;
110
122
@@ -117,6 +129,8 @@ describe('getBatchEventProcessor', () => {
117
129
it ( 'uses exponential backoff with default parameters when retryOptions is provided without backoff values' , ( ) => {
118
130
const options = {
119
131
eventDispatcher : getMockEventDispatcher ( ) ,
132
+ defaultFlushInterval : 1000 ,
133
+ defaultBatchSize : 10 ,
120
134
retryOptions : { } ,
121
135
} ;
122
136
@@ -133,6 +147,8 @@ describe('getBatchEventProcessor', () => {
133
147
it ( 'uses exponential backoff with provided backoff values in retryOptions' , ( ) => {
134
148
const options = {
135
149
eventDispatcher : getMockEventDispatcher ( ) ,
150
+ defaultFlushInterval : 1000 ,
151
+ defaultBatchSize : 10 ,
136
152
retryOptions : { minBackoff : 1000 , maxBackoff : 2000 } ,
137
153
} ;
138
154
@@ -149,48 +165,54 @@ describe('getBatchEventProcessor', () => {
149
165
it ( 'uses a IntervalRepeater with default flush interval and adds a startup log if flushInterval is not provided' , ( ) => {
150
166
const options = {
151
167
eventDispatcher : getMockEventDispatcher ( ) ,
168
+ defaultFlushInterval : 12345 ,
169
+ defaultBatchSize : 77 ,
152
170
} ;
153
171
154
172
const processor = getBatchEventProcessor ( options ) ;
155
173
156
174
expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
157
175
const usedRepeater = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . dispatchRepeater ;
158
176
expect ( Object . is ( usedRepeater , MockIntervalRepeater . mock . instances [ 0 ] ) ) . toBe ( true ) ;
159
- expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , DEFAULT_EVENT_FLUSH_INTERVAL ) ;
177
+ expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , 12345 ) ;
160
178
161
179
const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
162
180
expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
163
181
level : LogLevel . Warn ,
164
182
message : 'Invalid flushInterval %s, defaulting to %s' ,
165
- params : [ undefined , DEFAULT_EVENT_FLUSH_INTERVAL ] ,
183
+ params : [ undefined , 12345 ] ,
166
184
} ] ) ) ;
167
185
} ) ;
168
186
169
187
it ( 'uses default flush interval and adds a startup log if flushInterval is less than 1' , ( ) => {
170
188
const options = {
171
189
eventDispatcher : getMockEventDispatcher ( ) ,
172
190
flushInterval : - 1 ,
191
+ defaultFlushInterval : 12345 ,
192
+ defaultBatchSize : 77 ,
173
193
} ;
174
194
175
195
const processor = getBatchEventProcessor ( options ) ;
176
196
177
197
expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
178
198
const usedRepeater = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . dispatchRepeater ;
179
199
expect ( Object . is ( usedRepeater , MockIntervalRepeater . mock . instances [ 0 ] ) ) . toBe ( true ) ;
180
- expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , DEFAULT_EVENT_FLUSH_INTERVAL ) ;
200
+ expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , 12345 ) ;
181
201
182
202
const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
183
203
expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
184
204
level : LogLevel . Warn ,
185
205
message : 'Invalid flushInterval %s, defaulting to %s' ,
186
- params : [ - 1 , DEFAULT_EVENT_FLUSH_INTERVAL ] ,
206
+ params : [ - 1 , 12345 ] ,
187
207
} ] ) ) ;
188
208
} ) ;
189
209
190
210
it ( 'uses a IntervalRepeater with provided flushInterval and adds no startup log if provided flushInterval is valid' , ( ) => {
191
211
const options = {
192
212
eventDispatcher : getMockEventDispatcher ( ) ,
193
213
flushInterval : 12345 ,
214
+ defaultFlushInterval : 1000 ,
215
+ defaultBatchSize : 77 ,
194
216
} ;
195
217
196
218
const processor = getBatchEventProcessor ( options ) ;
0 commit comments