@@ -54,6 +54,27 @@ public function testTryLockJobAlreadyLockedFails()
54
54
$ this ->assertFalse ($ schedule ->tryLockJob ());
55
55
}
56
56
57
+ /**
58
+ * If the job is already locked but lock time less than 1 day ago, attempting to lock it again should fail
59
+ */
60
+ public function testTryLockJobAlreadyLockedSucceeds ()
61
+ {
62
+ $ offsetInThePast = 2 *24 *60 *60 ;
63
+
64
+ $ oldSchedule = $ this ->scheduleFactory ->create ()
65
+ ->setCronExpr ("* * * * * " )
66
+ ->setJobCode ("test_job " )
67
+ ->setStatus (Schedule::STATUS_RUNNING )
68
+ ->setCreatedAt (strftime ('%Y-%m-%d %H:%M:%S ' , $ this ->dateTime ->gmtTimestamp () - $ offsetInThePast ))
69
+ ->setScheduledAt (strftime ('%Y-%m-%d %H:%M ' , $ this ->dateTime ->gmtTimestamp () - $ offsetInThePast + 60 ))
70
+ ->setExecutedAt (strftime ('%Y-%m-%d %H:%M ' , $ this ->dateTime ->gmtTimestamp () - $ offsetInThePast + 61 ));
71
+ $ oldSchedule ->save ();
72
+
73
+ $ schedule = $ this ->createSchedule ("test_job " , Schedule::STATUS_PENDING );
74
+
75
+ $ this ->assertTrue ($ schedule ->tryLockJob ());
76
+ }
77
+
57
78
/**
58
79
* If there's a job already locked, should not be able to lock another job
59
80
*/
@@ -82,9 +103,10 @@ public function testTryLockJobDifferentJobLocked()
82
103
* @param string $jobCode
83
104
* @param string $status
84
105
* @param int $timeOffset
106
+ * @param int $executionTimeOffset
85
107
* @return Schedule
86
108
*/
87
- private function createSchedule ($ jobCode , $ status , $ timeOffset = 0 )
109
+ private function createSchedule ($ jobCode , $ status , $ timeOffset = 0 , $ executionTimeOffset = 0 )
88
110
{
89
111
$ schedule = $ this ->scheduleFactory ->create ()
90
112
->setCronExpr ("* * * * * " )
0 commit comments