-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathSentinelClientTest.php
More file actions
83 lines (66 loc) · 2.92 KB
/
SentinelClientTest.php
File metadata and controls
83 lines (66 loc) · 2.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace Clue\Tests\React\Redis;
use Clue\React\Redis\Io\StreamingClient;
use Clue\React\Redis\SentinelClient;
use React\EventLoop\StreamSelectLoop;
use function Clue\React\Block\await;
class SentinelClientTest extends TestCase
{
/** @var StreamSelectLoop */
private $loop;
/** @var string */
private $masterUri;
/** @var array */
private $uris;
/** @var string */
private $masterName;
public function setUp(): void
{
$this->masterUri = getenv('REDIS_URI') ?: '';
if ($this->masterUri === '') {
$this->markTestSkipped('No REDIS_URI environment variable given for Sentinel tests');
}
$uris = getenv('REDIS_URIS') ?: '';
if ($uris === '') {
$this->markTestSkipped('No REDIS_URIS environment variable given for Sentinel tests');
}
$this->uris = array_map('trim', explode(',', $uris));
$this->masterName = getenv('REDIS_SENTINEL_MASTER') ?: '';
if ($this->masterName === '') {
$this->markTestSkipped('No REDIS_SENTINEL_MASTER environment variable given for Sentinel tests');
}
$this->loop = new StreamSelectLoop();
}
public function testMasterAddress()
{
$redis = new SentinelClient($this->uris, $this->masterName, null, $this->loop);
$masterAddressPromise = $redis->masterAddress();
$masterAddress = await($masterAddressPromise, $this->loop);
$this->assertEquals(str_replace('localhost', '127.0.0.1', $this->masterUri), $masterAddress);
}
public function testMasterConnectionWithParams()
{
$redis = new SentinelClient($this->uris, $this->masterName, null, $this->loop);
$masterConnectionPromise = $redis->masterConnection('/1', ['timeout' => 0.5]);
$masterConnection = await($masterConnectionPromise, $this->loop);
$this->assertInstanceOf(StreamingClient::class, $masterConnection);
$pong = await($masterConnection->ping(), $this->loop);
$this->assertEquals('PONG', $pong);
}
public function testConnectionFail()
{
$redis = new SentinelClient(['128.128.0.1:26379?timeout=0.1'], $this->masterName, null, $this->loop);
$masterConnectionPromise = $redis->masterConnection();
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Connection to redis://128.128.0.1:26379?timeout=0.1 timed out after 0.1 seconds');
await($masterConnectionPromise, $this->loop);
}
public function testConnectionSkipInvalid()
{
$redis = new SentinelClient(array_merge(['128.128.0.1:26379?timeout=0.1'], $this->uris), $this->masterName, null, $this->loop);
$masterConnectionPromise = $redis->masterConnection('/1', ['timeout' => 5]);
$masterConnection = await($masterConnectionPromise, $this->loop);
$this->assertInstanceOf(StreamingClient::class, $masterConnection);
}
}