@@ -875,7 +875,7 @@ describe('BatchEventProcessor', async () => {
875
875
} ) ;
876
876
877
877
describe ( 'retryFailedEvents' , ( ) => {
878
- it ( 'should disptach only failed events from the store and not dispatch queued events' , async ( ) => {
878
+ it ( 'should dispatch only failed events from the store and not dispatch queued events' , async ( ) => {
879
879
const eventDispatcher = getMockDispatcher ( ) ;
880
880
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
881
881
mockDispatch . mockResolvedValue ( { } ) ;
@@ -921,7 +921,7 @@ describe('BatchEventProcessor', async () => {
921
921
] ) ) ;
922
922
} ) ;
923
923
924
- it ( 'should disptach only failed events from the store and not dispatch events that are being dispatched' , async ( ) => {
924
+ it ( 'should dispatch only failed events from the store and not dispatch events that are being dispatched' , async ( ) => {
925
925
const eventDispatcher = getMockDispatcher ( ) ;
926
926
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
927
927
const mockResult1 = resolvablePromise ( ) ;
@@ -977,7 +977,7 @@ describe('BatchEventProcessor', async () => {
977
977
] ) ) ;
978
978
} ) ;
979
979
980
- it ( 'should disptach events in correct batch size and separate events with differnt contexts in separate batch' , async ( ) => {
980
+ it ( 'should dispatch events in correct batch size and separate events with differnt contexts in separate batch' , async ( ) => {
981
981
const eventDispatcher = getMockDispatcher ( ) ;
982
982
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
983
983
mockDispatch . mockResolvedValue ( { } ) ;
@@ -1023,7 +1023,7 @@ describe('BatchEventProcessor', async () => {
1023
1023
} ) ;
1024
1024
1025
1025
describe ( 'when failedEventRepeater is fired' , ( ) => {
1026
- it ( 'should disptach only failed events from the store and not dispatch queued events' , async ( ) => {
1026
+ it ( 'should dispatch only failed events from the store and not dispatch queued events' , async ( ) => {
1027
1027
const eventDispatcher = getMockDispatcher ( ) ;
1028
1028
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
1029
1029
mockDispatch . mockResolvedValue ( { } ) ;
@@ -1071,7 +1071,7 @@ describe('BatchEventProcessor', async () => {
1071
1071
] ) ) ;
1072
1072
} ) ;
1073
1073
1074
- it ( 'should disptach only failed events from the store and not dispatch events that are being dispatched' , async ( ) => {
1074
+ it ( 'should dispatch only failed events from the store and not dispatch events that are being dispatched' , async ( ) => {
1075
1075
const eventDispatcher = getMockDispatcher ( ) ;
1076
1076
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
1077
1077
const mockResult1 = resolvablePromise ( ) ;
@@ -1129,7 +1129,7 @@ describe('BatchEventProcessor', async () => {
1129
1129
] ) ) ;
1130
1130
} ) ;
1131
1131
1132
- it ( 'should disptach events in correct batch size and separate events with differnt contexts in separate batch' , async ( ) => {
1132
+ it ( 'should dispatch events in correct batch size and separate events with differnt contexts in separate batch' , async ( ) => {
1133
1133
const eventDispatcher = getMockDispatcher ( ) ;
1134
1134
const mockDispatch : MockInstance < typeof eventDispatcher . dispatchEvent > = eventDispatcher . dispatchEvent ;
1135
1135
mockDispatch . mockResolvedValue ( { } ) ;
@@ -1277,7 +1277,7 @@ describe('BatchEventProcessor', async () => {
1277
1277
expect ( failedEventRepeater . stop ) . toHaveBeenCalledOnce ( ) ;
1278
1278
} ) ;
1279
1279
1280
- it ( 'should disptach the events in queue using the closing dispatcher if available' , async ( ) => {
1280
+ it ( 'should dispatch the events in queue using the closing dispatcher if available' , async ( ) => {
1281
1281
const eventDispatcher = getMockDispatcher ( ) ;
1282
1282
const closingEventDispatcher = getMockDispatcher ( ) ;
1283
1283
closingEventDispatcher . dispatchEvent . mockResolvedValue ( { } ) ;
@@ -1408,4 +1408,76 @@ describe('BatchEventProcessor', async () => {
1408
1408
await expect ( processor . onTerminated ( ) ) . resolves . not . toThrow ( ) ;
1409
1409
} ) ;
1410
1410
} ) ;
1411
+
1412
+ describe ( 'flushImmediately' , ( ) => {
1413
+ it ( 'should dispatch the events in queue using the closing dispatcher if available' , async ( ) => {
1414
+ const eventDispatcher = getMockDispatcher ( ) ;
1415
+ const closingEventDispatcher = getMockDispatcher ( ) ;
1416
+ closingEventDispatcher . dispatchEvent . mockResolvedValue ( { } ) ;
1417
+
1418
+ const dispatchRepeater = getMockRepeater ( ) ;
1419
+ const failedEventRepeater = getMockRepeater ( ) ;
1420
+
1421
+ const processor = new BatchEventProcessor ( {
1422
+ eventDispatcher,
1423
+ closingEventDispatcher,
1424
+ dispatchRepeater,
1425
+ failedEventRepeater,
1426
+ batchSize : 100 ,
1427
+ } ) ;
1428
+
1429
+ processor . start ( ) ;
1430
+ await processor . onRunning ( ) ;
1431
+
1432
+ const events : ProcessableEvent [ ] = [ ] ;
1433
+ for ( let i = 0 ; i < 10 ; i ++ ) {
1434
+ const event = createImpressionEvent ( `id-${ i } ` ) ;
1435
+ events . push ( event ) ;
1436
+ await processor . process ( event ) ;
1437
+ }
1438
+
1439
+ expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 0 ) ;
1440
+ expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 0 ) ;
1441
+
1442
+ processor . flushImmediately ( ) ;
1443
+ expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1444
+ expect ( closingEventDispatcher . dispatchEvent ) . toHaveBeenCalledWith ( buildLogEvent ( events ) ) ;
1445
+
1446
+ expect ( processor . isRunning ( ) ) . toBe ( true ) ;
1447
+ } ) ;
1448
+
1449
+
1450
+ it ( 'should dispatch the events in queue using eventDispatcher if closingEventDispatcher is not available' , async ( ) => {
1451
+ const eventDispatcher = getMockDispatcher ( ) ;
1452
+ eventDispatcher . dispatchEvent . mockResolvedValue ( { } ) ;
1453
+
1454
+ const dispatchRepeater = getMockRepeater ( ) ;
1455
+ const failedEventRepeater = getMockRepeater ( ) ;
1456
+
1457
+ const processor = new BatchEventProcessor ( {
1458
+ eventDispatcher,
1459
+ dispatchRepeater,
1460
+ failedEventRepeater,
1461
+ batchSize : 100 ,
1462
+ } ) ;
1463
+
1464
+ processor . start ( ) ;
1465
+ await processor . onRunning ( ) ;
1466
+
1467
+ const events : ProcessableEvent [ ] = [ ] ;
1468
+ for ( let i = 0 ; i < 10 ; i ++ ) {
1469
+ const event = createImpressionEvent ( `id-${ i } ` ) ;
1470
+ events . push ( event ) ;
1471
+ await processor . process ( event ) ;
1472
+ }
1473
+
1474
+ expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 0 ) ;
1475
+
1476
+ processor . flushImmediately ( ) ;
1477
+ expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledTimes ( 1 ) ;
1478
+ expect ( eventDispatcher . dispatchEvent ) . toHaveBeenCalledWith ( buildLogEvent ( events ) ) ;
1479
+
1480
+ expect ( processor . isRunning ( ) ) . toBe ( true ) ;
1481
+ } ) ;
1482
+ } ) ;
1411
1483
} ) ;
0 commit comments