forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueRedisQueueTest.php
More file actions
96 lines (71 loc) · 3.91 KB
/
QueueRedisQueueTest.php
File metadata and controls
96 lines (71 loc) · 3.91 KB
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
<?php
use Mockery as m;
class QueueRedisQueueTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testPushProperlyPushesJobOntoRedis()
{
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getRandomId'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(array('job' => 'foo', 'data' => array('data'), 'id' => 'foo', 'attempts' => 1)));
$id = $queue->push('foo', array('data'));
$this->assertEquals('foo', $id);
}
public function testDelayedPushProperlyPushesJobOntoRedis()
{
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getSeconds', 'getTime', 'getRandomId'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$queue->expects($this->once())->method('getSeconds')->with(1)->will($this->returnValue(1));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
$redis->shouldReceive('zadd')->once()->with(
'queues:default:delayed',
2,
json_encode(array('job' => 'foo', 'data' => array('data'), 'id' => 'foo', 'attempts' => 1))
);
$id = $queue->later(1, 'foo', array('data'));
$this->assertEquals('foo', $id);
}
public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
{
$date = Carbon\Carbon::now();
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getSeconds', 'getTime', 'getRandomId'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo'));
$queue->expects($this->once())->method('getSeconds')->with($date)->will($this->returnValue(1));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
$redis->shouldReceive('zadd')->once()->with(
'queues:default:delayed',
2,
json_encode(array('job' => 'foo', 'data' => array('data'), 'id' => 'foo', 'attempts' => 1))
);
$queue->later($date, 'foo', array('data'));
}
public function testPopProperlyPopsJobOffOfRedis()
{
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getTime', 'migrateAllExpiredJobs'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
$queue->expects($this->once())->method('migrateAllExpiredJobs')->with($this->equalTo('queues:default'));
$redis->shouldReceive('lpop')->once()->with('queues:default')->andReturn('foo');
$redis->shouldReceive('zadd')->once()->with('queues:default:reserved', 61, 'foo');
$result = $queue->pop();
$this->assertInstanceOf('Illuminate\Queue\Jobs\RedisJob', $result);
}
public function testReleaseMethod()
{
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getTime'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
$redis->shouldReceive('zadd')->once()->with('queues:default:delayed', 2, json_encode(array('attempts' => 2)));
$queue->release('default', json_encode(array('attempts' => 1)), 1, 2);
}
public function testMigrateExpiredJobs()
{
$queue = $this->getMock('Illuminate\Queue\RedisQueue', array('getTime'), array($redis = m::mock('Illuminate\Redis\Database'), 'default'));
$queue->expects($this->once())->method('getTime')->will($this->returnValue(1));
$redis->shouldReceive('zrangebyscore')->once()->with('from', '-inf', 1)->andReturn(array('foo', 'bar'));
$redis->shouldReceive('zremrangebyscore')->once()->with('from', '-inf', 1);
$redis->shouldReceive('rpush')->once()->with('to', 'foo', 'bar');
$queue->migrateExpiredJobs('from', 'to');
}
}