Added isConnected() method to client to work around disconnect issue with test suite.

This commit is contained in:
Nathan Osman 2013-07-01 21:51:48 -07:00
parent 32f01b33cb
commit 2c4b533124
3 changed files with 14 additions and 1 deletions

View File

@ -46,6 +46,12 @@ namespace QRedis
*/ */
void disconnectFromHost(); 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 * @brief Sends the specified command to the Redis server
* @param command the command to execute * @param command the command to execute

View File

@ -88,6 +88,11 @@ void Client::disconnectFromHost()
d->socket.disconnectFromHost(); d->socket.disconnectFromHost();
} }
bool Client::isConnected() const
{
return d->socket.state() == QAbstractSocket::ConnectedState;
}
Request * Client::sendCommand(const QString & command) Request * Client::sendCommand(const QString & command)
{ {
d->socket.write(QString("%1\r\n").arg(command).toUtf8()); d->socket.write(QString("%1\r\n").arg(command).toUtf8());

View File

@ -11,5 +11,7 @@ void TestClient::initTestCase()
void TestClient::cleanupTestCase() void TestClient::cleanupTestCase()
{ {
client.disconnectFromHost(); client.disconnectFromHost();
QVERIFY(client.waitForDisconnected());
if(client.isConnected())
QVERIFY(client.waitForDisconnected());
} }