Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
m3m0r7 committed May 5, 2021
1 parent fd75cd3 commit d089754
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/Coroutine/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,41 @@ public function testGetDataKeyInCoroutine()
{
$data1 = null;
$data2 = null;
$data3 = null;

$coroutineId1 = null;
$coroutineId2 = null;
\Swoole\Coroutine\run(function () use (&$data1, &$data2, &$coroutineId1, &$coroutineId2) {
$coroutineId3 = null;

\Swoole\Coroutine\run(function () use (&$data1, &$data2, &$data3, &$coroutineId1, &$coroutineId2, &$coroutineId3) {
Context::setData('foo', 'bar');

$data1 = Context::getData('foo');
$data2 = 'baz';
$data2 = 'swoole';

$coroutineId1 = Context::getRequestedCoroutineId();
$coroutineId2 = -1;
$coroutineId3 = -1;

go(function () use (&$data2, &$coroutineId2) {
go(function () use (&$data2, &$data3, &$coroutineId2, &$coroutineId3) {
$data2 = Context::getData('foo');
$coroutineId2 = Context::getRequestedCoroutineId();

// test nested coroutine
go(function () use (&$data3, &$coroutineId3) {
$data3 = Context::getData('foo');
$coroutineId3 = Context::getRequestedCoroutineId();
});
});
});

$this->assertSame('bar', $data1);
$this->assertSame($data1, $data2);
$this->assertSame($data2, $data3);
$this->assertSame($coroutineId1, $coroutineId2);
$this->assertSame($coroutineId2, $coroutineId3);

}

public function testClear()
Expand Down

0 comments on commit d089754

Please sign in to comment.