Repository navigation
Expand file tree
/
Copy pathChannelManagerTest.php
More file actions
59 lines (51 loc) · 1.5 KB
/
Copy pathChannelManagerTest.php
File metadata and controls
59 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Coroutine\Channel;
use Hyperf\Coroutine\Channel\Manager as ChannelManager;
use Hyperf\Engine\Channel;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
use function Hyperf\Coroutine\go;
/**
* @internal
* @coversNothing
*/
#[CoversNothing]
class ChannelManagerTest extends TestCase
{
public function testChannelManager()
{
$manager = new ChannelManager();
$chan = $manager->get(1, true);
$this->assertInstanceOf(Channel::class, $chan);
$chan = $manager->get(1);
$this->assertInstanceOf(Channel::class, $chan);
go(function () use ($chan) {
usleep(10 * 1000);
$chan->push('Hello World.');
});
$this->assertSame('Hello World.', $chan->pop());
$manager->close(1);
$this->assertTrue($chan->isClosing());
$this->assertNull($manager->get(1));
}
public function testChannelFlush()
{
$manager = new ChannelManager();
$manager->get(1, true);
$manager->get(2, true);
$manager->get(4, true);
$manager->get(5, true);
$this->assertSame(4, count($manager->getChannels()));
$manager->flush();
$this->assertSame(0, count($manager->getChannels()));
}
}