Skip to content

Commit fed5b60

Browse files
ddevsrclaude
andcommitted
test: skip live Sentinel tests when no Sentinel is reachable
CI only provides a plain Redis server on 127.0.0.1:6379, not a Redis Sentinel. The live Sentinel tests therefore failed in CI: master discovery threw, CacheFactory::getHandler fell back to the DummyHandler, whose save() always returns true but stores nothing, so get() returned null. Probe for a Sentinel on 127.0.0.1:26379 and mark the test skipped when none is reachable. Locally (or in CI with a Sentinel service added) the tests run as before. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 31a746a commit fed5b60

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎tests/system/Cache/Handlers/PredisHandlerTest.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,18 @@ public function testReconnect(): void
201201
* Live test that runs when predis/predis is installed (see the class-level
202202
* Group('CacheLive') attribute). It assumes a local Redis Sentinel is
203203
* reachable at 127.0.0.1:26379 monitoring the "mymaster" service, mirroring
204-
* how the other live Redis tests assume a server on 127.0.0.1:6379.
204+
* how the other live Redis tests assume a server on 127.0.0.1:6379. Skipped
205+
* when no Sentinel is running (CI only provides a plain Redis server).
205206
*/
206207
public function testInitializeWithSentinel(): void
207208
{
209+
$socket = @stream_socket_client('tcp://127.0.0.1:26379', $errno, $errstr, 1.0);
210+
211+
if ($socket === false) {
212+
$this->markTestSkipped('Redis Sentinel not reachable at 127.0.0.1:26379.');
213+
}
214+
215+
fclose($socket);
208216
$config = new Cache();
209217
$config->redis = [
210218
'sentinel' => [

‎tests/system/Cache/Handlers/RedisHandlerTest.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,18 @@ public function testReconnect(): void
243243
* Live test that runs when the redis extension is loaded (see the class-level
244244
* RequiresPhpExtension attribute). It assumes a local Redis Sentinel is
245245
* reachable at 127.0.0.1:26379 monitoring the "mymaster" service, mirroring
246-
* how the other live Redis tests assume a server on 127.0.0.1:6379.
246+
* how the other live Redis tests assume a server on 127.0.0.1:6379. Skipped
247+
* when no Sentinel is running (CI only provides a plain Redis server).
247248
*/
248249
public function testInitializeWithSentinel(): void
249250
{
251+
$socket = @stream_socket_client('tcp://127.0.0.1:26379', $errno, $errstr, 1.0);
252+
253+
if ($socket === false) {
254+
$this->markTestSkipped('Redis Sentinel not reachable at 127.0.0.1:26379.');
255+
}
256+
257+
fclose($socket);
250258
$config = new Cache();
251259
$config->redis = [
252260
'sentinel' => [

‎tests/system/Cache/Handlers/RedisSentinelTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public function testDiscoverMasterThrowsWhenNoNodes(): void
3232
RedisSentinel::discoverMaster([], 'mymaster');
3333
}
3434

35+
/**
36+
* Skips the test when no Redis Sentinel is reachable at 127.0.0.1:26379.
37+
* This keeps CI (which only provides a plain Redis server) green while the
38+
* live test still runs locally when a Sentinel is available.
39+
*/
40+
private function skipUnlessSentinel(): void
41+
{
42+
$socket = @stream_socket_client('tcp://127.0.0.1:26379', $errno, $errstr, 1.0);
43+
44+
if ($socket === false) {
45+
$this->markTestSkipped('Redis Sentinel not reachable at 127.0.0.1:26379.');
46+
}
47+
48+
fclose($socket);
49+
}
50+
3551
#[RequiresPhpExtension('redis')]
3652
public function testDiscoverMasterThrowsWhenAllNodesUnreachable(): void
3753
{
@@ -55,6 +71,7 @@ public function testDiscoverMasterThrowsWhenAllNodesUnreachable(): void
5571
#[RequiresPhpExtension('redis')]
5672
public function testDiscoverMasterLive(): void
5773
{
74+
$this->skipUnlessSentinel();
5875
$address = RedisSentinel::discoverMaster(
5976
[['host' => '127.0.0.1', 'port' => 26379]],
6077
'mymaster',

0 commit comments

Comments
 (0)