@@ -19,7 +19,7 @@ import { EventWithId, BatchEventProcessor } from './batch_event_processor';
19
19
import { getMockSyncCache } from '../tests/mock/mock_cache' ;
20
20
import { createImpressionEvent } from '../tests/mock/create_event' ;
21
21
import { ProcessableEvent } from './event_processor' ;
22
- import { formatEvents } from './event_builder/build_event_v1' ;
22
+ import { buildLogEvent } from './event_builder/build_event_v1' ;
23
23
import { resolvablePromise } from '../utils/promise/resolvablePromise' ;
24
24
import { advanceTimersByTime } from '../../tests/testUtils' ;
25
25
import { getMockLogger } from '../tests/mock/mock_logger' ;
@@ -139,9 +139,9 @@ describe('QueueingEventProcessor', async () => {
139
139
await exhaustMicrotasks ( ) ;
140
140
141
141
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 3 ) ;
142
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ events [ 0 ] , events [ 1 ] ] ) ) ;
143
- expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( [ events [ 2 ] , events [ 3 ] ] ) ) ;
144
- expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( formatEvents ( [ events [ 4 ] ] ) ) ;
142
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ events [ 0 ] , events [ 1 ] ] ) ) ;
143
+ expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ events [ 2 ] , events [ 3 ] ] ) ) ;
144
+ expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ events [ 4 ] ] ) ) ;
145
145
} ) ;
146
146
} ) ;
147
147
@@ -202,7 +202,7 @@ describe('QueueingEventProcessor', async () => {
202
202
await processor . process ( event ) ;
203
203
204
204
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
205
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( events ) ) ;
205
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( events ) ) ;
206
206
207
207
events = [ event ] ;
208
208
for ( let i = 101 ; i < 200 ; i ++ ) {
@@ -217,7 +217,7 @@ describe('QueueingEventProcessor', async () => {
217
217
await processor . process ( event ) ;
218
218
219
219
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 2 ) ;
220
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( events ) ) ;
220
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( events ) ) ;
221
221
} ) ;
222
222
223
223
it ( 'should flush queue is context of the new event is different and enqueue the new event' , async ( ) => {
@@ -250,11 +250,11 @@ describe('QueueingEventProcessor', async () => {
250
250
await processor . process ( newEvent ) ;
251
251
252
252
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
253
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( events ) ) ;
253
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( events ) ) ;
254
254
255
255
await dispatchRepeater . execute ( 0 ) ;
256
256
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 2 ) ;
257
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( [ newEvent ] ) ) ;
257
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ newEvent ] ) ) ;
258
258
} ) ;
259
259
260
260
it ( 'should store the event in the eventStore with increasing ids' , async ( ) => {
@@ -313,7 +313,7 @@ describe('QueueingEventProcessor', async () => {
313
313
await dispatchRepeater . execute ( 0 ) ;
314
314
315
315
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
316
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( events ) ) ;
316
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( events ) ) ;
317
317
318
318
events = [ ] ;
319
319
for ( let i = 1 ; i < 15 ; i ++ ) {
@@ -324,7 +324,7 @@ describe('QueueingEventProcessor', async () => {
324
324
325
325
await dispatchRepeater . execute ( 0 ) ;
326
326
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 2 ) ;
327
- expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( events ) ) ;
327
+ expect ( eventDispatcher . dispatchEvent . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( events ) ) ;
328
328
} ) ;
329
329
330
330
it ( 'should not retry failed dispatch if retryConfig is not provided' , async ( ) => {
@@ -397,7 +397,7 @@ describe('QueueingEventProcessor', async () => {
397
397
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 4 ) ;
398
398
expect ( backoffController . backoff ) . toHaveBeenCalledTimes ( 3 ) ;
399
399
400
- const request = formatEvents ( events ) ;
400
+ const request = buildLogEvent ( events ) ;
401
401
for ( let i = 0 ; i < 4 ; i ++ ) {
402
402
expect ( eventDispatcher . dispatchEvent . mock . calls [ i ] [ 0 ] ) . toEqual ( request ) ;
403
403
}
@@ -444,7 +444,7 @@ describe('QueueingEventProcessor', async () => {
444
444
expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 201 ) ;
445
445
expect ( backoffController . backoff ) . toHaveBeenCalledTimes ( 200 ) ;
446
446
447
- const request = formatEvents ( events ) ;
447
+ const request = buildLogEvent ( events ) ;
448
448
for ( let i = 0 ; i < 201 ; i ++ ) {
449
449
expect ( eventDispatcher . dispatchEvent . mock . calls [ i ] [ 0 ] ) . toEqual ( request ) ;
450
450
}
@@ -723,7 +723,7 @@ describe('QueueingEventProcessor', async () => {
723
723
await exhaustMicrotasks ( ) ;
724
724
725
725
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 1 ) ;
726
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( failedEvents ) ) ;
726
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( failedEvents ) ) ;
727
727
728
728
const eventsInStore = [ ...cache . getAll ( ) . values ( ) ] . sort ( ( a , b ) => a . id < b . id ? - 1 : 1 ) . map ( e => e . event ) ;
729
729
expect ( eventsInStore ) . toEqual ( expect . arrayContaining ( [
@@ -761,7 +761,7 @@ describe('QueueingEventProcessor', async () => {
761
761
dispatchRepeater . execute ( 0 ) ;
762
762
await exhaustMicrotasks ( ) ;
763
763
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 1 ) ;
764
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ eventA , eventB ] ) ) ;
764
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ eventA , eventB ] ) ) ;
765
765
766
766
const failedEvents : ProcessableEvent [ ] = [ ] ;
767
767
@@ -776,7 +776,7 @@ describe('QueueingEventProcessor', async () => {
776
776
await exhaustMicrotasks ( ) ;
777
777
778
778
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 2 ) ;
779
- expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( failedEvents ) ) ;
779
+ expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( failedEvents ) ) ;
780
780
781
781
mockResult2 . resolve ( { } ) ;
782
782
await exhaustMicrotasks ( ) ;
@@ -826,10 +826,10 @@ describe('QueueingEventProcessor', async () => {
826
826
// events 0 1 4 5 6 7 have one context, and 2 3 have different context
827
827
// batches should be [0, 1], [2, 3], [4, 5, 6], [7]
828
828
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 4 ) ;
829
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 0 ] , failedEvents [ 1 ] ] ) ) ;
830
- expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 2 ] , failedEvents [ 3 ] ] ) ) ;
831
- expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 4 ] , failedEvents [ 5 ] , failedEvents [ 6 ] ] ) ) ;
832
- expect ( mockDispatch . mock . calls [ 3 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 7 ] ] ) ) ;
829
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 0 ] , failedEvents [ 1 ] ] ) ) ;
830
+ expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 2 ] , failedEvents [ 3 ] ] ) ) ;
831
+ expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 4 ] , failedEvents [ 5 ] , failedEvents [ 6 ] ] ) ) ;
832
+ expect ( mockDispatch . mock . calls [ 3 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 7 ] ] ) ) ;
833
833
} ) ;
834
834
} ) ;
835
835
@@ -873,7 +873,7 @@ describe('QueueingEventProcessor', async () => {
873
873
await exhaustMicrotasks ( ) ;
874
874
875
875
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 1 ) ;
876
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( failedEvents ) ) ;
876
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( failedEvents ) ) ;
877
877
878
878
const eventsInStore = [ ...cache . getAll ( ) . values ( ) ] . sort ( ( a , b ) => a . id < b . id ? - 1 : 1 ) . map ( e => e . event ) ;
879
879
expect ( eventsInStore ) . toEqual ( expect . arrayContaining ( [
@@ -913,7 +913,7 @@ describe('QueueingEventProcessor', async () => {
913
913
dispatchRepeater . execute ( 0 ) ;
914
914
await exhaustMicrotasks ( ) ;
915
915
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 1 ) ;
916
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ eventA , eventB ] ) ) ;
916
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ eventA , eventB ] ) ) ;
917
917
918
918
const failedEvents : ProcessableEvent [ ] = [ ] ;
919
919
@@ -928,7 +928,7 @@ describe('QueueingEventProcessor', async () => {
928
928
await exhaustMicrotasks ( ) ;
929
929
930
930
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 2 ) ;
931
- expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( failedEvents ) ) ;
931
+ expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( failedEvents ) ) ;
932
932
933
933
mockResult2 . resolve ( { } ) ;
934
934
await exhaustMicrotasks ( ) ;
@@ -980,10 +980,10 @@ describe('QueueingEventProcessor', async () => {
980
980
// events 0 1 4 5 6 7 have one context, and 2 3 have different context
981
981
// batches should be [0, 1], [2, 3], [4, 5, 6], [7]
982
982
expect ( mockDispatch ) . toHaveBeenCalledTimes ( 4 ) ;
983
- expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 0 ] , failedEvents [ 1 ] ] ) ) ;
984
- expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 2 ] , failedEvents [ 3 ] ] ) ) ;
985
- expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 4 ] , failedEvents [ 5 ] , failedEvents [ 6 ] ] ) ) ;
986
- expect ( mockDispatch . mock . calls [ 3 ] [ 0 ] ) . toEqual ( formatEvents ( [ failedEvents [ 7 ] ] ) ) ;
983
+ expect ( mockDispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 0 ] , failedEvents [ 1 ] ] ) ) ;
984
+ expect ( mockDispatch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 2 ] , failedEvents [ 3 ] ] ) ) ;
985
+ expect ( mockDispatch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 4 ] , failedEvents [ 5 ] , failedEvents [ 6 ] ] ) ) ;
986
+ expect ( mockDispatch . mock . calls [ 3 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ failedEvents [ 7 ] ] ) ) ;
987
987
} ) ;
988
988
} ) ;
989
989
@@ -1012,7 +1012,7 @@ describe('QueueingEventProcessor', async () => {
1012
1012
await dispatchRepeater . execute ( 0 ) ;
1013
1013
1014
1014
expect ( dispatchListener ) . toHaveBeenCalledTimes ( 1 ) ;
1015
- expect ( dispatchListener . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ event , event2 ] ) ) ;
1015
+ expect ( dispatchListener . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ event , event2 ] ) ) ;
1016
1016
} ) ;
1017
1017
1018
1018
it ( 'should remove event handler when function returned from onDispatch is called' , async ( ) => {
@@ -1041,7 +1041,7 @@ describe('QueueingEventProcessor', async () => {
1041
1041
await dispatchRepeater . execute ( 0 ) ;
1042
1042
1043
1043
expect ( dispatchListener ) . toHaveBeenCalledTimes ( 1 ) ;
1044
- expect ( dispatchListener . mock . calls [ 0 ] [ 0 ] ) . toEqual ( formatEvents ( [ event , event2 ] ) ) ;
1044
+ expect ( dispatchListener . mock . calls [ 0 ] [ 0 ] ) . toEqual ( buildLogEvent ( [ event , event2 ] ) ) ;
1045
1045
1046
1046
unsub ( ) ;
1047
1047
@@ -1119,7 +1119,7 @@ describe('QueueingEventProcessor', async () => {
1119
1119
1120
1120
processor . stop ( ) ;
1121
1121
expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1122
- expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledWith ( formatEvents ( events ) ) ;
1122
+ expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledWith ( buildLogEvent ( events ) ) ;
1123
1123
} ) ;
1124
1124
1125
1125
it ( 'should cancel retry of active dispatches' , async ( ) => {
0 commit comments