From 2b1542d7fee7e9ef14592e88c8a974ed4ea2eacf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 30 Jul 2015 17:53:46 +0200 Subject: Tested command loop with Ping command. Ping is a command that by definition doesn't affect the resource, and thus can be used at all times to check if the resource is still alive. --- common/commands.cpp | 2 ++ common/commands.h | 1 + common/listener.cpp | 3 +++ tests/resourcecommunicationtest.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/common/commands.cpp b/common/commands.cpp index 99313b9..221c211 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -55,6 +55,8 @@ QByteArray name(int commandId) return "Shutdown"; case NotificationCommand: return "Notification"; + case PingCommand: + return "Ping"; case CustomCommand: return "Custom"; }; diff --git a/common/commands.h b/common/commands.h index 1baedcc..da2438a 100644 --- a/common/commands.h +++ b/common/commands.h @@ -45,6 +45,7 @@ enum CommandIds { SearchSourceCommand, // need a buffer definition for this, but relies on Query API ShutdownCommand, NotificationCommand, + PingCommand, CustomCommand = 0xffff }; diff --git a/common/listener.cpp b/common/listener.cpp index 96d87be..8532ade 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -246,6 +246,9 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c m_server->close(); QTimer::singleShot(0, this, &Listener::quit); break; + case Akonadi2::Commands::PingCommand: + Log() << QString("\tReceived ping command from %1").arg(client.name); + break; default: if (commandId > Akonadi2::Commands::CustomCommand) { Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp index f1cef50..1ab516a 100644 --- a/tests/resourcecommunicationtest.cpp +++ b/tests/resourcecommunicationtest.cpp @@ -35,6 +35,31 @@ private Q_SLOTS: result.waitForFinished(); QVERIFY(!result.errorCode()); } + + void testCommandLoop() + { + const QByteArray resourceIdentifier("test"); + Listener listener(resourceIdentifier); + Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + resourceAccess.open(); + + const int count = 500; + int complete = 0; + int errors = 0; + for (int i = 0; i < count; i++) { + auto result = resourceAccess.sendCommand(Akonadi2::Commands::PingCommand) + .then([&complete]() { + complete++; + }, + [&errors, &complete](int error, const QString &msg) { + qWarning() << msg; + errors++; + complete++; + }).exec(); + } + QTRY_COMPARE(complete, count); + QVERIFY(!errors); + } }; QTEST_MAIN(ResourceCommunicationTest) -- cgit v1.2.3