Skip to content

Commit 06c4ed1

Browse files
committed
tests for AsyncWorkerCommand
1 parent 1d3a6a8 commit 06c4ed1

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

commands/AsyncWorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function actionExecute($queueName = null)
2424
public function actionDaemon($queueName = null)
2525
{
2626
/** @var AsyncTask $task */
27-
while ($task = \Yii::$app->async->waitAndReceive($queueName ?: AsyncTask::$queueName)) {
27+
while ($task = \Yii::$app->async->receiveTask($queueName ?: AsyncTask::$queueName, true)) {
2828
$task->execute();
2929
\Yii::$app->async->acknowledgeTask($task);
3030
}

tests/unit/BaseTestClass.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22
namespace bazilio\async\tests\unit;
33

4+
use bazilio\async\commands\AsyncWorkerCommand;
45
use bazilio\async\Exception;
56
use bazilio\async\models\AsyncExecuteTask;
67
use bazilio\async\models\AsyncTask;
8+
use yii\base\Module;
79

810
class TestTask extends AsyncTask
911
{
@@ -218,4 +220,32 @@ public function testSubscribe()
218220

219221
$this->assertNotFalse(\Yii::$app->async->receiveTask($task::$queueName, true));
220222
}
221-
}
223+
224+
public function testConsoleCommandDaemon() {
225+
if (get_called_class() == 'bazilio\async\tests\unit\AmqpTest') {
226+
$this->markTestSkipped('No support for AMQP yet');
227+
return;
228+
}
229+
230+
$task = new TestTask();
231+
\Yii::$app->async->sendTask($task);
232+
233+
$controller = new AsyncWorkerCommand('id', new Module('id'));
234+
235+
$this->setExpectedException('yii\db\Exception');
236+
$controller->actionDaemon($task::$queueName);
237+
238+
$this->assertFalse($this->async->receiveTask($task::$queueName));
239+
}
240+
241+
public function testConsoleCommandExecute() {
242+
$task = new TestTask();
243+
\Yii::$app->async->sendTask($task);
244+
245+
$controller = new AsyncWorkerCommand('id', new Module('id'));
246+
247+
$controller->actionExecute($task::$queueName);
248+
249+
$this->assertFalse($this->async->receiveTask($task::$queueName));
250+
}
251+
}

tests/unit/_config.redis.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
'hostname' => 'localhost',
99
'port' => 6379,
1010
'database' => 5,
11+
'connectionTimeout' => 1,
12+
'dataTimeout' => 1,
1113
],
1214
'async' => [
1315
'class' => 'bazilio\async\AsyncComponent',

0 commit comments

Comments
 (0)