diff --git a/tests/Coroutine/ContextTest.php b/tests/Coroutine/ContextTest.php index fcc29b5..9d9e99f 100644 --- a/tests/Coroutine/ContextTest.php +++ b/tests/Coroutine/ContextTest.php @@ -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()