diff --git a/src/Transport/Http.php b/src/Transport/Http.php index 9e9618d..5389e20 100644 --- a/src/Transport/Http.php +++ b/src/Transport/Http.php @@ -577,7 +577,7 @@ public function getRequestWrite(Query $query): CurlerRequest public function ping(): bool { $request = new CurlerRequest(); - $request->url($this->getUri())->verbose(false)->GET()->connectTimeOut($this->getConnectTimeOut()); + $request->url($this->getUri())->verbose(false)->GET()->timeOut($this->settings()->getTimeOut())->connectTimeOut($this->getConnectTimeOut()); $this->_curler->execOne($request); return trim($request->response()->body()) === 'Ok.'; diff --git a/tests/PingTimeoutTest.php b/tests/PingTimeoutTest.php new file mode 100644 index 0000000..25afb62 --- /dev/null +++ b/tests/PingTimeoutTest.php @@ -0,0 +1,61 @@ +assertNotFalse($server, "Could not start local test server: $errstr"); + + $address = stream_socket_get_name($server, false); + [$host, $port] = explode(':', $address); + + $config = [ + 'host' => $host, + 'port' => (int) $port, + 'username' => '', + 'password' => '', + ]; + + $start_time = microtime(true); + + try { + $db = new Client($config); + // High connect timeout so it does not fire before the query timeout. + $db->setConnectTimeOut(5); + $db->setTimeout(1); + $db->ping(); + } catch (\Exception $e) { + // Expected — ping() will throw when the query timeout fires. + } finally { + fclose($server); + } + + $elapsed = round(microtime(true) - $start_time); + $this->assertEquals(1, $elapsed); + } +}