From 0f75ad4b96ec5994c022109278cad28a43255793 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 3 Dec 2015 11:17:08 +0100 Subject: 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. --- tests/dummyresourcetest.cpp | 1 + tests/resourcecommunicationtest.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 20c725f..b8711a2 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -35,6 +35,7 @@ private Q_SLOTS: DummyResource::removeFromDisk("org.kde.dummy.instance1"); auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); + Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } void init() 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: QTRY_COMPARE(complete, count); QVERIFY(!errors); } + + void testResourceAccessReuse() + { + qDebug(); + const QByteArray resourceIdentifier("test"); + Listener listener(resourceIdentifier); + Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + resourceAccess.open(); + + const int count = 10; + int complete = 0; + int errors = 0; + for (int i = 0; i < count; i++) { + resourceAccess.sendCommand(Akonadi2::Commands::PingCommand) + .then([&complete]() { + complete++; + }, + [&errors, &complete](int error, const QString &msg) { + qWarning() << msg; + errors++; + complete++; + }).then([&resourceAccess]() { + resourceAccess.close(); + resourceAccess.open(); + }).exec().waitForFinished(); + } + QTRY_COMPARE(complete, count); + QVERIFY(!errors); + } }; QTEST_MAIN(ResourceCommunicationTest) -- cgit v1.2.3