Skip to content

Commit

Permalink
tests for AsyncWorkerCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
bazilio91 committed Nov 15, 2015
1 parent 1d3a6a8 commit 06c4ed1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion commands/AsyncWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function actionExecute($queueName = null)
public function actionDaemon($queueName = null)
{
/** @var AsyncTask $task */
while ($task = \Yii::$app->async->waitAndReceive($queueName ?: AsyncTask::$queueName)) {
while ($task = \Yii::$app->async->receiveTask($queueName ?: AsyncTask::$queueName, true)) {
$task->execute();
\Yii::$app->async->acknowledgeTask($task);
}
Expand Down
32 changes: 31 additions & 1 deletion tests/unit/BaseTestClass.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
namespace bazilio\async\tests\unit;

use bazilio\async\commands\AsyncWorkerCommand;
use bazilio\async\Exception;
use bazilio\async\models\AsyncExecuteTask;
use bazilio\async\models\AsyncTask;
use yii\base\Module;

class TestTask extends AsyncTask
{
Expand Down Expand Up @@ -218,4 +220,32 @@ public function testSubscribe()

$this->assertNotFalse(\Yii::$app->async->receiveTask($task::$queueName, true));
}
}

public function testConsoleCommandDaemon() {
if (get_called_class() == 'bazilio\async\tests\unit\AmqpTest') {
$this->markTestSkipped('No support for AMQP yet');
return;
}

$task = new TestTask();
\Yii::$app->async->sendTask($task);

$controller = new AsyncWorkerCommand('id', new Module('id'));

$this->setExpectedException('yii\db\Exception');
$controller->actionDaemon($task::$queueName);

$this->assertFalse($this->async->receiveTask($task::$queueName));
}

public function testConsoleCommandExecute() {
$task = new TestTask();
\Yii::$app->async->sendTask($task);

$controller = new AsyncWorkerCommand('id', new Module('id'));

$controller->actionExecute($task::$queueName);

$this->assertFalse($this->async->receiveTask($task::$queueName));
}
}
2 changes: 2 additions & 0 deletions tests/unit/_config.redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
'hostname' => 'localhost',
'port' => 6379,
'database' => 5,
'connectionTimeout' => 1,
'dataTimeout' => 1,
],
'async' => [
'class' => 'bazilio\async\AsyncComponent',
Expand Down

0 comments on commit 06c4ed1

Please sign in to comment.