From bf00b2c3a0fbfbdcbd7c5f4ab519049dc02c1263 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 30 Jan 2015 01:10:37 +0100 Subject: Shutdown command for synchronizers, used by the dummyresourcetest. Otherwise the synchronizer keeps a Storage object alive, while the tests deletes the db. This causes subsequent writes to fail in the next test. --- common/clientapi.cpp | 12 ++++++++++++ common/clientapi.h | 2 ++ common/commands.h | 1 + synchronizer/listener.cpp | 6 ++++++ tests/dummyresourcetest.cpp | 4 +++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 2a4b603..260b6b8 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -1,5 +1,7 @@ #include "clientapi.h" +#include "resourceaccess.h" +#include "commands.h" namespace async { @@ -35,4 +37,14 @@ QString getTypeName() } // namespace Domain +void Store::shutdown(const QString &identifier) +{ + Akonadi2::ResourceAccess resourceAccess(identifier); + resourceAccess.open(); + resourceAccess.sendCommand(Akonadi2::Commands::ShutdownCommand).then([](Async::Future &f){ + //TODO wait for disconnect + f.setFinished(); + }).exec().waitForFinished(); +} + } // namespace Akonadi2 diff --git a/common/clientapi.h b/common/clientapi.h index 542039e..71317a1 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -488,6 +488,8 @@ public: auto facade = FacadeFactory::instance().getFacade(resourceIdentifier); facade.remove(domainObject); } + + static void shutdown(const QString &resourceIdentifier); }; } diff --git a/common/commands.h b/common/commands.h index c63bb47..26729dc 100644 --- a/common/commands.h +++ b/common/commands.h @@ -42,6 +42,7 @@ enum CommandIds { ModifyEntityCommand, CreateEntityCommand, SearchSourceCommand, // need a buffer definition for this, but relies on Query API + ShutdownCommand, CustomCommand = 0xffff }; diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index f52e48c..d191bb8 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp @@ -243,6 +243,12 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); } break; + case Akonadi2::Commands::ShutdownCommand: + log(QString("\tReceived shutdown command from %1").arg(client.name)); + callback(); + m_server->close(); + emit noClients(); + return; default: if (commandId > Akonadi2::Commands::CustomCommand) { loadResource(); diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 6548659..b185664 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -34,11 +34,13 @@ private Q_SLOTS: void cleanup() { - //TODO kill the synchronizer first? + Akonadi2::Store::shutdown("org.kde.dummy"); removeFromDisk("org.kde.dummy"); removeFromDisk("org.kde.dummy.userqueue"); removeFromDisk("org.kde.dummy.synchronizerqueue"); removeFromDisk("org.kde.dummy.index.uid"); + auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + QVERIFY(factory); } void testProcessCommand() -- cgit v1.2.3