Skip to content

Commit 3d9e69a

Browse files
author
Alex Mayfield
committed
Adjust timing in testRateLimit() so less likely to fail.
Also, use CakePHP Time() when doing rate limiting for consistency.
1 parent beaa2ea commit 3d9e69a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Model/Table/QueuedTasksTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function requestJob(array $capabilities, $group = null) {
266266
$this->save($data, ['fieldList' => ['id', 'failed', 'failure_message']]);
267267
}
268268
//save last fetch by type for Rate Limiting.
269-
$this->rateHistory[$data['jobtype']] = time();
269+
$this->rateHistory[$data['jobtype']] = (new Time())->toUnixString() ;
270270
return $data;
271271
}
272272

tests/TestCase/Model/Table/QueuedTasksTableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function testRateLimit() {
292292
'name' => 'task1',
293293
'timeout' => 101,
294294
'retries' => 2,
295-
'rate' => 1,
295+
'rate' => 2,
296296
],
297297
'dummytask' => [
298298
'name' => 'dummytask',
@@ -324,15 +324,15 @@ public function testRateLimit() {
324324
$this->assertEquals('dummytask', $tmp['jobtype']);
325325
$this->assertNull(unserialize($tmp['data']));
326326

327-
usleep(500000);
327+
usleep(100000);
328328
//and again.
329329
$this->QueuedTasks->clearKey();
330330
$tmp = $this->QueuedTasks->requestJob($capabilities);
331331
$this->assertEquals('dummytask', $tmp['jobtype']);
332332
$this->assertNull(unserialize($tmp['data']));
333333

334334
//Then some time passes
335-
sleep(1);
335+
sleep(2);
336336

337337
//Now we should get task1-2
338338
$this->QueuedTasks->clearKey();
@@ -347,7 +347,7 @@ public function testRateLimit() {
347347
$this->assertNull(unserialize($tmp['data']));
348348

349349
//Then some more time passes
350-
sleep(1);
350+
sleep(2);
351351

352352
//Now we should get task1-3
353353
$this->QueuedTasks->clearKey();

0 commit comments

Comments
 (0)