@@ -10,7 +10,13 @@ import { getResult, getMlResult } from '../routes/__mocks__/request_responses';
1010import { signalRulesAlertType } from './signal_rule_alert_type' ;
1111import { alertsMock , AlertServicesMock } from '../../../../../alerts/server/mocks' ;
1212import { ruleStatusServiceFactory } from './rule_status_service' ;
13- import { getGapBetweenRuns , getListsClient , getExceptions , sortExceptionItems } from './utils' ;
13+ import {
14+ getGapBetweenRuns ,
15+ getGapMaxCatchupRatio ,
16+ getListsClient ,
17+ getExceptions ,
18+ sortExceptionItems ,
19+ } from './utils' ;
1420import { RuleExecutorOptions } from './types' ;
1521import { searchAfterAndBulkCreate } from './search_after_bulk_create' ;
1622import { scheduleNotificationActions } from '../notifications/schedule_notification_actions' ;
@@ -97,6 +103,7 @@ describe('rules_notification_alert_type', () => {
97103 exceptionsWithValueLists : [ ] ,
98104 } ) ;
99105 ( searchAfterAndBulkCreate as jest . Mock ) . mockClear ( ) ;
106+ ( getGapMaxCatchupRatio as jestMock ) . mockClear ( ) ;
100107 ( searchAfterAndBulkCreate as jest . Mock ) . mockResolvedValue ( {
101108 success : true ,
102109 searchAfterTimes : [ ] ,
@@ -126,22 +133,39 @@ describe('rules_notification_alert_type', () => {
126133 } ) ;
127134
128135 describe ( 'executor' , ( ) => {
129- it ( 'should warn about the gap between runs' , async ( ) => {
130- ( getGapBetweenRuns as jest . Mock ) . mockReturnValue ( moment . duration ( 1000 ) ) ;
136+ it ( 'should warn about the gap between runs if gap is very large' , async ( ) => {
137+ ( getGapBetweenRuns as jest . Mock ) . mockReturnValue ( moment . duration ( 100 , 'm' ) ) ;
138+ ( getGapMaxCatchupRatio as jest . Mock ) . mockReturnValue ( {
139+ maxCatchup : 4 ,
140+ ratio : 20 ,
141+ gapDiffInUnits : 95 ,
142+ } ) ;
131143 await alert . executor ( payload ) ;
132144 expect ( logger . warn ) . toHaveBeenCalled ( ) ;
133145 expect ( logger . warn . mock . calls [ 0 ] [ 0 ] ) . toContain (
134- 'a few seconds (1000ms ) has passed since last rule execution, and signals may have been missed.'
146+ '2 hours (6000000ms ) has passed since last rule execution, and signals may have been missed.'
135147 ) ;
136148 expect ( ruleStatusService . error ) . toHaveBeenCalled ( ) ;
137149 expect ( ruleStatusService . error . mock . calls [ 0 ] [ 0 ] ) . toContain (
138- 'a few seconds (1000ms ) has passed since last rule execution, and signals may have been missed.'
150+ '2 hours (6000000ms ) has passed since last rule execution, and signals may have been missed.'
139151 ) ;
140152 expect ( ruleStatusService . error . mock . calls [ 0 ] [ 1 ] ) . toEqual ( {
141- gap : 'a few seconds ' ,
153+ gap : '2 hours ' ,
142154 } ) ;
143155 } ) ;
144156
157+ it ( 'should NOT warn about the gap between runs if gap small' , async ( ) => {
158+ ( getGapBetweenRuns as jest . Mock ) . mockReturnValue ( moment . duration ( 1 , 'm' ) ) ;
159+ ( getGapMaxCatchupRatio as jest . Mock ) . mockReturnValue ( {
160+ maxCatchup : 1 ,
161+ ratio : 1 ,
162+ gapDiffInUnits : 1 ,
163+ } ) ;
164+ await alert . executor ( payload ) ;
165+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 0 ) ;
166+ expect ( ruleStatusService . error ) . toHaveBeenCalledTimes ( 0 ) ;
167+ } ) ;
168+
145169 it ( "should set refresh to 'wait_for' when actions are present" , async ( ) => {
146170 const ruleAlert = getResult ( ) ;
147171 ruleAlert . actions = [
0 commit comments