This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FactoryTest.php
109 lines (91 loc) 路 2.87 KB
/
FactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Hodor\Database\Adapter;
use PHPUnit\Framework\TestCase;
abstract class FactoryTest extends TestCase
{
/**
* @covers ::__construct
* @covers ::getBufferWorker
* @covers ::getSuperqueuer
* @covers ::getDequeuer
* @covers ::<private>
*/
public function testFactoryGeneratesWorkingObjects()
{
$factory = $this->getTestFactory();
$buffer_worker = $factory->getBufferWorker();
$superqueuer = $factory->getSuperqueuer();
$dequeuer = $factory->getDequeuer();
$uniqid = uniqid();
$buffer_worker->bufferJob('fast_jobs', $this->getJob([
'name' => "job-{$uniqid}-1",
'options' => ['mutex_id' => "mutex-{$uniqid}"],
]));
$buffer_worker->bufferJob('fast_jobs', $this->getJob([
'name' => "job-{$uniqid}-2",
'options' => ['mutex_id' => "mutex-{$uniqid}"],
]));
$job_to_finish = null;
foreach ($superqueuer->getJobsToRunGenerator() as $job) {
$this->assertSame("job-{$uniqid}-1", $job['job_name']);
$superqueuer->markJobAsQueued($job);
$job_to_finish = $job;
$job_to_finish['started_running_at'] = date('c');
}
foreach ($superqueuer->getJobsToRunGenerator() as $job) {
$this->fail('There should be no jobs that can be queued since the mutex is in use.');
}
$dequeuer->markJobAsSuccessful($job_to_finish);
foreach ($superqueuer->getJobsToRunGenerator() as $job) {
$this->assertSame("job-{$uniqid}-2", $job['job_name']);
}
}
/**
* @covers ::__construct
* @covers ::getBufferWorker
* @covers ::<private>
*/
public function testBufferWorkerIsReused()
{
$factory = $this->getTestFactory();
$this->assertSame($factory->getBufferWorker(), $factory->getBufferWorker());
}
/**
* @covers ::__construct
* @covers ::getSuperqueuer
* @covers ::<private>
*/
public function testSuperqueuerIsReused()
{
$factory = $this->getTestFactory();
$this->assertSame($factory->getSuperqueuer(), $factory->getSuperqueuer());
}
/**
* @covers ::__construct
* @covers ::getDequeuer
* @covers ::<private>
*/
public function testDequeuerIsReused()
{
$factory = $this->getTestFactory();
$this->assertSame($factory->getDequeuer(), $factory->getDequeuer());
}
/**
* @return FactoryInterface
*/
abstract protected function getTestFactory();
/**
* @param array $job
* @return array
*/
private function getJob(array $job)
{
return array_replace_recursive([
'params' => [],
'meta' => [
'buffered_at' => date('c'),
'buffered_from' => gethostname(),
],
], $job);
}
}