summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-30 17:53:46 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-30 17:54:56 +0200
commit2b1542d7fee7e9ef14592e88c8a974ed4ea2eacf (patch)
treebbdf1a27c5d275f1b2214c62d303fd0b9a39b5c9
parent93b208cc95114e39f5d3379e66646c94e70b6a02 (diff)
downloadsink-2b1542d7fee7e9ef14592e88c8a974ed4ea2eacf.tar.gz
sink-2b1542d7fee7e9ef14592e88c8a974ed4ea2eacf.zip
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.
-rw-r--r--common/commands.cpp2
-rw-r--r--common/commands.h1
-rw-r--r--common/listener.cpp3
-rw-r--r--tests/resourcecommunicationtest.cpp25
4 files changed, 31 insertions, 0 deletions
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)
55 return "Shutdown"; 55 return "Shutdown";
56 case NotificationCommand: 56 case NotificationCommand:
57 return "Notification"; 57 return "Notification";
58 case PingCommand:
59 return "Ping";
58 case CustomCommand: 60 case CustomCommand:
59 return "Custom"; 61 return "Custom";
60 }; 62 };
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 {
45 SearchSourceCommand, // need a buffer definition for this, but relies on Query API 45 SearchSourceCommand, // need a buffer definition for this, but relies on Query API
46 ShutdownCommand, 46 ShutdownCommand,
47 NotificationCommand, 47 NotificationCommand,
48 PingCommand,
48 CustomCommand = 0xffff 49 CustomCommand = 0xffff
49}; 50};
50 51
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
246 m_server->close(); 246 m_server->close();
247 QTimer::singleShot(0, this, &Listener::quit); 247 QTimer::singleShot(0, this, &Listener::quit);
248 break; 248 break;
249 case Akonadi2::Commands::PingCommand:
250 Log() << QString("\tReceived ping command from %1").arg(client.name);
251 break;
249 default: 252 default:
250 if (commandId > Akonadi2::Commands::CustomCommand) { 253 if (commandId > Akonadi2::Commands::CustomCommand) {
251 Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; 254 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:
35 result.waitForFinished(); 35 result.waitForFinished();
36 QVERIFY(!result.errorCode()); 36 QVERIFY(!result.errorCode());
37 } 37 }
38
39 void testCommandLoop()
40 {
41 const QByteArray resourceIdentifier("test");
42 Listener listener(resourceIdentifier);
43 Akonadi2::ResourceAccess resourceAccess(resourceIdentifier);
44 resourceAccess.open();
45
46 const int count = 500;
47 int complete = 0;
48 int errors = 0;
49 for (int i = 0; i < count; i++) {
50 auto result = resourceAccess.sendCommand(Akonadi2::Commands::PingCommand)
51 .then<void>([&complete]() {
52 complete++;
53 },
54 [&errors, &complete](int error, const QString &msg) {
55 qWarning() << msg;
56 errors++;
57 complete++;
58 }).exec();
59 }
60 QTRY_COMPARE(complete, count);
61 QVERIFY(!errors);
62 }
38}; 63};
39 64
40QTEST_MAIN(ResourceCommunicationTest) 65QTEST_MAIN(ResourceCommunicationTest)