Skip to content

Commit

Permalink
Test delayed release()
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Leonovich committed Jul 6, 2015
1 parent 04267b7 commit ec281fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ Or put back into the queue in case it cannot be executed:

```php
$this->queue->release($task->getId());
// or

// for ttl-like queues you can specify a delay
$this->queue->release($task->getId(), ['delay' => 30]);
```

Expand Down
27 changes: 22 additions & 5 deletions tests/Integration/Ttl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Tarantool\Queue\Tests\Integration;

use Tarantool\Queue\States;

trait Ttl
{
/**
Expand Down Expand Up @@ -59,15 +61,30 @@ public function testPriority()
*/
public function testDelay()
{
$task = $this->queue->take(.1);
$task = $this->queue->peek(0);
$this->assertTask($task, 0, States::DELAYED, 'delay_1');

$this->assertNull($task);
sleep(1);

$task = $this->queue->peek(0);
$this->assertTask($task, 0, States::READY, 'delay_1');
}

/**
* @eval queue.tube['%tube_name%']:put('release_0')
* @eval queue.tube['%tube_name%']:take()
*/
public function testDelayedRelease()
{
$this->queue->release(0, ['delay' => 1]);

$task = $this->queue->peek(0);
$this->assertTask($task, 0, States::DELAYED, 'release_0');

sleep(1);
$task = $this->queue->take(.1);

$this->assertTaskInstance($task);
$this->assertSame('delay_1', $task->getData());
$task = $this->queue->peek(0);
$this->assertTask($task, 0, States::READY, 'release_0');
}

/**
Expand Down

0 comments on commit ec281fb

Please sign in to comment.