Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
208511b
Merge pull request #81 from swooletw/develop
albertcht Jun 12, 2018
51dea74
Merge pull request #84 from swooletw/develop
albertcht Jun 12, 2018
9adb5bf
remove ext-swoole dependency from composer.json becauseof unknown com…
albertcht Jun 12, 2018
32102cf
Merge pull request #87 from swooletw/develop
albertcht Jun 12, 2018
82b0913
fix sandbox enable
albertcht Jun 12, 2018
7e1a9cb
Merge pull request #88 from swooletw/develop
albertcht Jun 12, 2018
b30fc40
Update README.md
albertcht Jun 16, 2018
3b816be
fix parser test in swoole 4.0
albertcht Jun 16, 2018
e5f1cf7
Merge pull request #91 from swooletw/develop
albertcht Jun 16, 2018
b32376c
Update ISSUE_TEMPLATE.md
albertcht Jul 21, 2018
d30f44b
Update ISSUE_TEMPLATE.md
albertcht Jul 27, 2018
7c11d75
Update ISSUE_TEMPLATE.md
albertcht Jul 28, 2018
39229ef
Supported Swoole async task queue driver
damonto Sep 1, 2018
0e97d59
Fix AsyncTaskJob not found
damonto Sep 1, 2018
214b619
Remove ServiceProvider
damonto Sep 1, 2018
db8ffe2
Fix unable create swoole_server
damonto Sep 1, 2018
fc59fa9
fix conflicts
damonto Sep 2, 2018
4034bf3
fix conflicts again
damonto Sep 2, 2018
b7249f6
Merged coroutine feature
damonto Sep 2, 2018
83bcd34
Add phpunit test cases
damonto Sep 2, 2018
5783325
Change comments format
damonto Sep 2, 2018
58087d0
Remove getJobExpiration because of unused
damonto Sep 2, 2018
362fbc0
Don't override createObjectPayload
damonto Sep 2, 2018
d4656bf
Compatible with older versions
damonto Sep 2, 2018
a840966
Fix undefined method getContainer()
damonto Sep 2, 2018
1544615
Move getContainer method to SwooleTaskJob
damonto Sep 2, 2018
6792ed8
Uncomment code
damonto Sep 2, 2018
18c8444
Swoole_timer_after first parameter is microsecond
damonto Sep 2, 2018
7828ef2
Merge branch 'feature/coroutine_feature' into feature/swoole_async_task
albertcht Sep 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add phpunit test cases
  • Loading branch information
damonto committed Sep 2, 2018
commit 83bcd346b023a56c3e86ae72a19dfffd89f9f7f6
9 changes: 7 additions & 2 deletions src/Server/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,15 @@ public function onTask($server, $taskId, $srcWorkerId, $data)
&& $data['action'] === Websocket::PUSH_ACTION) {
$this->pushMessage($server, $data['data'] ?? []);
}
} else {
(new SwooleTaskJob($this->container, $server, $data, $taskId, $srcWorkerId))->fire();
} elseif (is_string($data)) {
$decoded= json_decode($data, true);

if (JSON_ERROR_NONE === json_last_error() && $decoded['type'] === 'queue') {
(new SwooleTaskJob($this->container, $server, $data, $taskId, $srcWorkerId))->fire();
}
}
} catch (Throwable $e) {
dump($e);
$this->logServerError($e);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Task/SwooleTaskQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SwooleTW\Http\Task;

use Exception;
use Illuminate\Queue\Queue;
use Illuminate\Contracts\Queue\Queue as QueueContract;

Expand Down Expand Up @@ -48,7 +49,7 @@ public function push($job, $data = '', $queue = null)
*/
public function pushRaw($payload, $queue = null, array $options = [])
{
return $this->swoole->task($payload, $queue);
return $this->swoole->task($payload, ! is_numeric($queue) ? 1 : (int) $queue);
}

/**
Expand Down Expand Up @@ -76,6 +77,7 @@ public function later($delay, $job, $data = '', $queue = null)
protected function createObjectPayload($job)
{
return [
'type' => 'queue',
'maxTries' => $job->tries ?? null,
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
'timeout' => $job->timeout ?? null,
Expand Down
18 changes: 18 additions & 0 deletions tests/Task/FakeJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SwooleTW\Http\Tests\Task;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class FakeJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;

public function handle()
{
//
}
}
39 changes: 39 additions & 0 deletions tests/Task/SwooleJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace SwooleTW\Http\Tests\Task;

use Mockery as m;
use SwooleTW\Http\Tests\TestCase;
use Illuminate\Container\Container;
use SwooleTW\Http\Task\SwooleTaskJob;

class SwooleJobTest extends TestCase
{
public function testFireProperlyCallsTheJobHandler()
{
$job = $this->getJob();
$job->getContainer()->shouldReceive('make')->once()->with('foo')->andReturn($handler = m::mock('stdClass'));
$handler->shouldReceive('fire')->once()->with($job, ['data']);
$job->fire();
}

protected function getJob()
{
return new SwooleTaskJob(
m::mock(Container::class),
$this->getServer(),
json_encode(['job' => 'foo', 'data' => ['data'], 'attempts' => 1]),
1, 1
);
}

protected function getServer()
{
$server = m::mock('server');
$server->shouldReceive('on');
$server->taskworker = false;
$server->master_pid = -1;

return $server;
}
}
31 changes: 31 additions & 0 deletions tests/Task/SwooleQueueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace SwooleTW\Http\Tests\Task;

use Mockery as m;
use SwooleTW\Http\Tests\TestCase;
use SwooleTW\Http\Task\SwooleTaskQueue;

class SwooleQueueTest extends TestCase
{
public function testPushProperlyPushesJobOntoSwoole()
{
$server = $this->getServer();

$queue = new SwooleTaskQueue($server);
$server->shouldReceive('task');
$queue->push(new FakeJob);
}

protected function getServer()
{
$server = m::mock('server');
$server->shouldReceive('on');
$server->taskworker = false;
$server->master_pid = -1;

return $server;
}
}