summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/imapresource/tests/CMakeLists.txt6
-rw-r--r--examples/imapresource/tests/imapmailsyncbenchmark.cpp127
-rw-r--r--examples/imapresource/tests/populatemailbox.sh27
3 files changed, 160 insertions, 0 deletions
diff --git a/examples/imapresource/tests/CMakeLists.txt b/examples/imapresource/tests/CMakeLists.txt
index 29ae918..c252a4f 100644
--- a/examples/imapresource/tests/CMakeLists.txt
+++ b/examples/imapresource/tests/CMakeLists.txt
@@ -14,4 +14,10 @@ target_link_libraries(imapserverproxytest sink_resource_imap)
14target_link_libraries(imapmailtest sink_resource_imap) 14target_link_libraries(imapmailtest sink_resource_imap)
15target_link_libraries(imapmailsynctest sink_resource_imap) 15target_link_libraries(imapmailsynctest sink_resource_imap)
16 16
17manual_tests (
18 imapmailsyncbenchmark
19)
20target_link_libraries(imapmailsyncbenchmark sink_resource_imap)
21
17install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) 22install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resetmailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
23install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/populatemailbox.sh DESTINATION bin PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
diff --git a/examples/imapresource/tests/imapmailsyncbenchmark.cpp b/examples/imapresource/tests/imapmailsyncbenchmark.cpp
new file mode 100644
index 0000000..c00e795
--- /dev/null
+++ b/examples/imapresource/tests/imapmailsyncbenchmark.cpp
@@ -0,0 +1,127 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include <QtTest>
20#include <QTcpSocket>
21
22#include <tests/mailsynctest.h>
23#include "../imapresource.h"
24#include "../imapserverproxy.h"
25
26#include "common/test.h"
27#include "common/domain/applicationdomaintype.h"
28#include "common/store.h"
29#include "common/resourcecontrol.h"
30
31using namespace Sink;
32using namespace Sink::ApplicationDomain;
33
34SINK_DEBUG_AREA("ImapMailSyncBenchmark")
35
36/**
37 * Test of complete system using the imap resource.
38 *
39 * This test requires the imap resource installed.
40 */
41class ImapMailSyncBenchmark : public QObject
42{
43 Q_OBJECT
44
45 bool isBackendAvailable()
46 {
47 QTcpSocket socket;
48 socket.connectToHost("localhost", 993);
49 return socket.waitForConnected(200);
50 }
51
52 void resetTestEnvironment()
53 {
54 system("populatemailbox.sh");
55 }
56
57 Sink::ApplicationDomain::SinkResource createResource()
58 {
59 auto resource = ApplicationDomain::ImapResource::create("account1");
60 resource.setProperty("server", "localhost");
61 resource.setProperty("port", 993);
62 resource.setProperty("username", "doe");
63 resource.setProperty("password", "doe");
64 return resource;
65 }
66
67 void removeResourceFromDisk(const QByteArray &identifier)
68 {
69 ::ImapResource::removeFromDisk(identifier);
70 }
71
72 QByteArray mResourceInstanceIdentifier;
73 QByteArrayList mCapabilities;
74
75private slots:
76
77 void initTestCase()
78 {
79 Test::initTest();
80 QVERIFY(isBackendAvailable());
81 resetTestEnvironment();
82 auto resource = createResource();
83 QVERIFY(!resource.identifier().isEmpty());
84
85 VERIFYEXEC(Store::create(resource));
86
87 mResourceInstanceIdentifier = resource.identifier();
88 mCapabilities = resource.getProperty("capabilities").value<QByteArrayList>();
89 }
90
91 void cleanup()
92 {
93 //TODO the shutdown job fails if the resource is already shut down
94 // VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier));
95 ResourceControl::shutdown(mResourceInstanceIdentifier).exec().waitForFinished();
96 removeResourceFromDisk(mResourceInstanceIdentifier);
97 }
98
99 void init()
100 {
101 qDebug();
102 qDebug() << "-----------------------------------------";
103 qDebug();
104 VERIFYEXEC(ResourceControl::start(mResourceInstanceIdentifier));
105 }
106
107 void testSync()
108 {
109 Sink::Query query;
110 query.resources << mResourceInstanceIdentifier;
111 query.request<Folder::Name>().request<Folder::SpecialPurpose>();
112
113 QTime time;
114 time.start();
115
116 // Ensure all local data is processed
117 VERIFYEXEC(Store::synchronize(query));
118 SinkLog() << "Sync took: " << Sink::Log::TraceTime(time.elapsed());
119
120 VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources));
121 SinkLog() << "Total took: " << Sink::Log::TraceTime(time.elapsed());
122 }
123};
124
125QTEST_MAIN(ImapMailSyncBenchmark)
126
127#include "imapmailsyncbenchmark.moc"
diff --git a/examples/imapresource/tests/populatemailbox.sh b/examples/imapresource/tests/populatemailbox.sh
new file mode 100644
index 0000000..a435df7
--- /dev/null
+++ b/examples/imapresource/tests/populatemailbox.sh
@@ -0,0 +1,27 @@
1#!/bin/bash
2
3sudo echo "sam user.doe.* cyrus c" | cyradm --auth PLAIN -u cyrus -w admin localhost
4sudo echo "dm user.doe.*" | cyradm --auth PLAIN -u cyrus -w admin localhost
5sudo echo "cm user.doe.test" | cyradm --auth PLAIN -u cyrus -w admin localhost
6sudo echo "cm user.doe.Drafts" | cyradm --auth PLAIN -u cyrus -w admin localhost
7sudo echo "cm user.doe.Trash" | cyradm --auth PLAIN -u cyrus -w admin localhost
8sudo echo "sam user.doe cyrus c" | cyradm --auth PLAIN -u cyrus -w admin localhost
9
10# for i in `seq 1 5000`;
11# do
12# # sudo cp /work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S /var/spool/imap/d/user/doe/test/$i.
13# done
14# Because this is way faster than a loop
15sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{1..1000}.
16sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{1001..2000}.
17sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{2001..3000}.
18sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{3001..4000}.
19sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{4001..5000}.
20sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{5001..6000}.
21sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{6001..7000}.
22sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{7001..8000}.
23sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{8001..9000}.
24sudo tee </work/source/Sink/examples/imapresource/tests/data/1365777830.R28.localhost.localdomain\:2\,S >/dev/null /var/spool/imap/d/user/doe/test/{9001..10000}.
25
26sudo chown -R cyrus:mail /var/spool/imap/d/user/doe/test
27sudo /usr/lib/cyrus-imapd/reconstruct "user.doe.test"