@@ -621,9 +621,7 @@ describe('Task Runner', () => {
621621 expect ( await taskRunner . run ( ) ) . toMatchInlineSnapshot ( `
622622 Object {
623623 "runAt": 1970-01-01T00:00:10.000Z,
624- "state": Object {
625- "previousStartedAt": 1970-01-01T00:00:00.000Z,
626- },
624+ "state": Object {},
627625 }
628626 ` ) ;
629627 expect ( taskRunnerFactoryInitializerParams . logger . error ) . toHaveBeenCalledWith (
@@ -727,9 +725,7 @@ describe('Task Runner', () => {
727725 expect ( runnerResult ) . toMatchInlineSnapshot ( `
728726 Object {
729727 "runAt": 1970-01-01T00:00:10.000Z,
730- "state": Object {
731- "previousStartedAt": 1970-01-01T00:00:00.000Z,
732- },
728+ "state": Object {},
733729 }
734730 ` ) ;
735731
@@ -781,9 +777,7 @@ describe('Task Runner', () => {
781777 expect ( runnerResult ) . toMatchInlineSnapshot ( `
782778 Object {
783779 "runAt": 1970-01-01T00:05:00.000Z,
784- "state": Object {
785- "previousStartedAt": 1970-01-01T00:00:00.000Z,
786- },
780+ "state": Object {},
787781 }
788782 ` ) ;
789783 } ) ;
@@ -814,9 +808,7 @@ describe('Task Runner', () => {
814808 expect ( runnerResult ) . toMatchInlineSnapshot ( `
815809 Object {
816810 "runAt": 1970-01-01T00:05:00.000Z,
817- "state": Object {
818- "previousStartedAt": 1970-01-01T00:00:00.000Z,
819- },
811+ "state": Object {},
820812 }
821813 ` ) ;
822814 } ) ;
@@ -846,13 +838,48 @@ describe('Task Runner', () => {
846838 expect ( runnerResult ) . toMatchInlineSnapshot ( `
847839 Object {
848840 "runAt": 1970-01-01T00:05:00.000Z,
849- "state": Object {
850- "previousStartedAt": 1970-01-01T00:00:00.000Z,
851- },
841+ "state": Object {},
852842 }
853843 ` ) ;
854844 } ) ;
855845
846+ test ( `doesn't change previousStartedAt when it fails to run` , async ( ) => {
847+ const originalAlertSate = {
848+ previousStartedAt : '1970-01-05T00:00:00.000Z' ,
849+ } ;
850+
851+ alertType . executor . mockImplementation (
852+ ( { services : executorServices } : AlertExecutorOptions ) => {
853+ throw new Error ( 'OMG' ) ;
854+ }
855+ ) ;
856+
857+ const taskRunner = new TaskRunner (
858+ alertType ,
859+ {
860+ ...mockedTaskInstance ,
861+ state : originalAlertSate ,
862+ } ,
863+ taskRunnerFactoryInitializerParams
864+ ) ;
865+
866+ alertsClient . get . mockResolvedValueOnce ( mockedAlertTypeSavedObject ) ;
867+ encryptedSavedObjectsClient . getDecryptedAsInternalUser . mockResolvedValueOnce ( {
868+ id : '1' ,
869+ type : 'alert' ,
870+ attributes : {
871+ apiKey : Buffer . from ( '123:abc' ) . toString ( 'base64' ) ,
872+ } ,
873+ references : [ ] ,
874+ } ) ;
875+
876+ const runnerResult = await taskRunner . run ( ) ;
877+
878+ expect ( runnerResult . state . previousStartedAt ) . toEqual (
879+ new Date ( originalAlertSate . previousStartedAt )
880+ ) ;
881+ } ) ;
882+
856883 test ( 'avoids rescheduling a failed Alert Task Runner when it throws due to failing to fetch the alert' , async ( ) => {
857884 alertsClient . get . mockImplementation ( ( ) => {
858885 throw SavedObjectsErrorHelpers . createGenericNotFoundError ( 'task' , '1' ) ;
@@ -878,9 +905,7 @@ describe('Task Runner', () => {
878905 expect ( runnerResult ) . toMatchInlineSnapshot ( `
879906 Object {
880907 "runAt": undefined,
881- "state": Object {
882- "previousStartedAt": 1970-01-01T00:00:00.000Z,
883- },
908+ "state": Object {},
884909 }
885910 ` ) ;
886911 } ) ;
0 commit comments