Skip to content

Commit f98d381

Browse files
committed
adding tests
1 parent 57f2c2e commit f98d381

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Prometheus/Storage/Redis.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,15 @@ public function __construct(array $options = [])
104104

105105
/**
106106
* Sentinels discoverMaster
107-
* @return mixed[]
108107
*/
109-
public function getSentinelPrimary(): array
108+
public function updateSentinelPrimary()
110109
{
111110
$master = $this->sentinel->getMaster();
112-
111+
113112
if (is_array($master)) {
114-
$options['host'] = $master['ip'];
115-
$options['port'] = $master['port'];
113+
$this->options['host'] = $master['ip'];
114+
$this->options['port'] = $master['port'];
116115
}
117-
return $options;
118116
}
119117

120118
/**
@@ -289,7 +287,7 @@ private function ensureOpenConnection(): void
289287
$retries = 0;
290288
while ($retries <= $reconnect) {
291289
try {
292-
$this->options = $this->getSentinelPrimary();
290+
$this->updateSentinelPrimary();
293291
$this->connectToServer();
294292
break;
295293
} catch (\RedisException $e) {
@@ -335,7 +333,7 @@ private function ensureOpenConnection(): void
335333
* @throws StorageException
336334
*/
337335
private function connectToServer(): void
338-
{
336+
{
339337
$connection_successful = false;
340338
if ($this->options['persistent_connections'] !== false) {
341339
$connection_successful = $this->redis->pconnect(

tests/Test/Prometheus/Storage/RedisSentinelTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ public function itShouldThrowAnExceptionOnPrimaryFailure(): void
8686
*/
8787
public function itShouldGetMaster(): void
8888
{
89-
$redis = new Redis(['host' => '/dev/null', 'sentinel' => ['host'=>REDIS_SENTINEL_HOST, 'enable' => true, 'service' => 'myprimary']]);
89+
$redis = new Redis(['host' => '/dev/null',
90+
'sentinel' => ['host'=>REDIS_SENTINEL_HOST, 'enable' => true, 'service' => 'myprimary']
91+
]);
9092

9193
$redis->collect();
9294
$redis->wipeStorage();
95+
$this->expectNotToPerformAssertions();
9396
}
9497
}

0 commit comments

Comments
 (0)