From 2c4b5331249f17891c226dd1ca3cdff9f2bb1056 Mon Sep 17 00:00:00 2001 From: Nathan Osman Date: Mon, 1 Jul 2013 21:51:48 -0700 Subject: [PATCH] Added isConnected() method to client to work around disconnect issue with test suite. --- include/qredis/client.h | 6 ++++++ src/client.cpp | 5 +++++ tests/testclient.cpp | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/qredis/client.h b/include/qredis/client.h index 66776d6..46fa353 100644 --- a/include/qredis/client.h +++ b/include/qredis/client.h @@ -46,6 +46,12 @@ namespace QRedis */ void disconnectFromHost(); + /** + * @brief Indicates whether the client is connected to a Redis server + * @return true if the client is connected + */ + bool isConnected() const; + /** * @brief Sends the specified command to the Redis server * @param command the command to execute diff --git a/src/client.cpp b/src/client.cpp index c6851a8..dd885fc 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -88,6 +88,11 @@ void Client::disconnectFromHost() d->socket.disconnectFromHost(); } +bool Client::isConnected() const +{ + return d->socket.state() == QAbstractSocket::ConnectedState; +} + Request * Client::sendCommand(const QString & command) { d->socket.write(QString("%1\r\n").arg(command).toUtf8()); diff --git a/tests/testclient.cpp b/tests/testclient.cpp index 15657d0..c61f860 100644 --- a/tests/testclient.cpp +++ b/tests/testclient.cpp @@ -11,5 +11,7 @@ void TestClient::initTestCase() void TestClient::cleanupTestCase() { client.disconnectFromHost(); - QVERIFY(client.waitForDisconnected()); + + if(client.isConnected()) + QVERIFY(client.waitForDisconnected()); }