Skip to content

Commit 9a318ee

Browse files
committed
returned and fix testConnectionTimeout
1 parent 76fcc88 commit 9a318ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/RedisConnectionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ public function testSerialize()
9999
$this->assertTrue($db2->ping());
100100
}
101101

102+
public function testConnectionTimeout()
103+
{
104+
$db = $this->getConnection(false);
105+
$db->configSet('timeout', 1);
106+
$this->assertTrue($db->ping());
107+
sleep(1);
108+
$this->assertTrue($db->ping());
109+
110+
$db->close();
111+
$db->on(Connection::EVENT_AFTER_OPEN, function() {
112+
// sleep 2 seconds after connect to make every command time out
113+
sleep(2);
114+
});
115+
116+
$exception = false;
117+
try {
118+
sleep(3);
119+
$db->ping();
120+
} catch (SocketException $e) {
121+
$exception = true;
122+
}
123+
$this->assertTrue($exception, 'SocketException should have been thrown.');
124+
}
125+
102126
public function testConnectionTimeoutRetry()
103127
{
104128
$logger = new Logger();

0 commit comments

Comments
 (0)