@@ -597,4 +597,49 @@ public function testDispatchCleanup()
597
597
598
598
$ this ->_observer ->dispatch ('' );
599
599
}
600
+
601
+ public function testMissedJobsCleanedInTime ()
602
+ {
603
+ $ jobConfig = [
604
+ 'test_group ' => ['test_job1 ' => ['instance ' => 'CronJob ' , 'method ' => 'execute ' ]],
605
+ ];
606
+
607
+ $ schedule = $ this ->getMockBuilder (
608
+ 'Magento\Cron\Model\Schedule '
609
+ )->disableOriginalConstructor ()->setMethods (
610
+ ['getExecutedAt ' , 'getScheduledAt ' , 'getStatus ' , 'delete ' , '__wakeup ' ]
611
+ )->getMock ();
612
+ $ schedule ->expects ($ this ->any ())->method ('getExecutedAt ' )->will ($ this ->returnValue (null ));
613
+ $ schedule ->expects ($ this ->any ())->method ('getScheduledAt ' )->will ($ this ->returnValue ('-1 day ' ));
614
+ $ schedule ->expects ($ this ->any ())->method ('getStatus ' )->will ($ this ->returnValue (Schedule::STATUS_MISSED ));
615
+
616
+ $ this ->_collection ->addItem ($ schedule );
617
+
618
+ $ this ->_config ->expects ($ this ->once ())->method ('getJobs ' )->will ($ this ->returnValue ($ jobConfig ));
619
+
620
+ $ this ->_cache ->expects ($ this ->at (0 ))->method ('load ' )->will ($ this ->returnValue (time () + 10000000 ));
621
+ $ this ->_cache ->expects ($ this ->at (1 ))->method ('load ' )->will ($ this ->returnValue (time () - 10000000 ));
622
+
623
+ $ this ->_scopeConfig ->expects ($ this ->any ())->method ('getValue ' )->will ($ this ->returnValue (0 ));
624
+
625
+ $ scheduleMock = $ this ->getMockBuilder ('Magento\Cron\Model\Schedule ' )->disableOriginalConstructor ()->getMock ();
626
+ $ scheduleMock ->expects ($ this ->any ())->method ('getCollection ' )->will ($ this ->returnValue ($ this ->_collection ));
627
+ $ this ->_scheduleFactory ->expects ($ this ->at (0 ))->method ('create ' )->will ($ this ->returnValue ($ scheduleMock ));
628
+
629
+ $ collection = $ this ->getMockBuilder (
630
+ 'Magento\Cron\Model\Resource\Schedule\Collection '
631
+ )->setMethods (
632
+ ['addFieldToFilter ' , 'load ' , '__wakeup ' ]
633
+ )->disableOriginalConstructor ()->getMock ();
634
+ $ collection ->expects ($ this ->any ())->method ('addFieldToFilter ' )->will ($ this ->returnSelf ());
635
+ $ collection ->expects ($ this ->any ())->method ('load ' )->will ($ this ->returnSelf ());
636
+ $ collection ->addItem ($ schedule );
637
+
638
+ $ scheduleMock = $ this ->getMockBuilder ('Magento\Cron\Model\Schedule ' )->disableOriginalConstructor ()->getMock ();
639
+ $ scheduleMock ->expects ($ this ->any ())->method ('getCollection ' )->will ($ this ->returnValue ($ collection ));
640
+ $ this ->_scheduleFactory ->expects ($ this ->at (1 ))->method ('create ' )->will ($ this ->returnValue ($ scheduleMock ));
641
+
642
+ $ this ->_observer ->dispatch ('' );
643
+
644
+ }
600
645
}
0 commit comments