summaryrefslogtreecommitdiffstats
path: root/tests/resourcecommunicationtest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-03 11:17:08 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-03 11:23:25 +0100
commit0f75ad4b96ec5994c022109278cad28a43255793 (patch)
tree6d7c6153025a79557dd1218d9be0a4a7cb7945c5 /tests/resourcecommunicationtest.cpp
parent2c80424031c195333cfa6785ea7ab57dc9613fa3 (diff)
downloadsink-0f75ad4b96ec5994c022109278cad28a43255793.tar.gz
sink-0f75ad4b96ec5994c022109278cad28a43255793.zip
Improved resource access caching
* Smarter caching. ResourceAccess instances close after a timeout, if not reused. * Introduced a start command to avoid race condition when sending commands to a resource that is currently shutting down. * We resend pending commands after we lost access to the resource * unexpectedly.
Diffstat (limited to 'tests/resourcecommunicationtest.cpp')
-rw-r--r--tests/resourcecommunicationtest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp
index fa2b5a1..18e9223 100644
--- a/tests/resourcecommunicationtest.cpp
+++ b/tests/resourcecommunicationtest.cpp
@@ -63,6 +63,35 @@ private Q_SLOTS:
63 QTRY_COMPARE(complete, count); 63 QTRY_COMPARE(complete, count);
64 QVERIFY(!errors); 64 QVERIFY(!errors);
65 } 65 }
66
67 void testResourceAccessReuse()
68 {
69 qDebug();
70 const QByteArray resourceIdentifier("test");
71 Listener listener(resourceIdentifier);
72 Akonadi2::ResourceAccess resourceAccess(resourceIdentifier);
73 resourceAccess.open();
74
75 const int count = 10;
76 int complete = 0;
77 int errors = 0;
78 for (int i = 0; i < count; i++) {
79 resourceAccess.sendCommand(Akonadi2::Commands::PingCommand)
80 .then<void>([&complete]() {
81 complete++;
82 },
83 [&errors, &complete](int error, const QString &msg) {
84 qWarning() << msg;
85 errors++;
86 complete++;
87 }).then<void>([&resourceAccess]() {
88 resourceAccess.close();
89 resourceAccess.open();
90 }).exec().waitForFinished();
91 }
92 QTRY_COMPARE(complete, count);
93 QVERIFY(!errors);
94 }
66}; 95};
67 96
68QTEST_MAIN(ResourceCommunicationTest) 97QTEST_MAIN(ResourceCommunicationTest)