diff options
-rw-r--r-- | hawd_defs/dummy_responsiveness | 7 | ||||
-rw-r--r-- | tests/dummyresourcebenchmark.cpp | 92 | ||||
-rw-r--r-- | tests/dummyresourcetest.cpp | 32 | ||||
-rw-r--r-- | tests/mailquerybenchmark.cpp | 8 | ||||
-rw-r--r-- | tests/testutils.h | 11 |
5 files changed, 57 insertions, 93 deletions
diff --git a/hawd_defs/dummy_responsiveness b/hawd_defs/dummy_responsiveness new file mode 100644 index 0000000..8c16c13 --- /dev/null +++ b/hawd_defs/dummy_responsiveness | |||
@@ -0,0 +1,7 @@ | |||
1 | { | ||
2 | "name": "Dummy resource command responsiveness", | ||
3 | "description": "Measure roundtriptime of command", | ||
4 | "columns": [ | ||
5 | { "name": "responsetime", "type": "float", "unit": "ms" } | ||
6 | ] | ||
7 | } | ||
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 674d4d6..57ad4de 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp | |||
@@ -74,10 +74,13 @@ private slots: | |||
74 | 74 | ||
75 | // Wait for notification | 75 | // Wait for notification |
76 | QUICK_TRY_VERIFY(gotNotification); | 76 | QUICK_TRY_VERIFY(gotNotification); |
77 | HAWD::Dataset dataset("dummy_responsiveness", m_hawdState); | ||
78 | HAWD::Dataset::Row row = dataset.row(); | ||
79 | row.setValue("responsetime", duration); | ||
80 | dataset.insertRow(row); | ||
81 | HAWD::Formatter::print(dataset); | ||
77 | 82 | ||
78 | QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); | ||
79 | VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); | 83 | VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); |
80 | qDebug() << "Single command took [ms]: " << duration; | ||
81 | } | 84 | } |
82 | 85 | ||
83 | void testWriteToFacade() | 86 | void testWriteToFacade() |
@@ -113,12 +116,6 @@ private slots: | |||
113 | row.setValue("total", (qreal)num / allProcessedTime); | 116 | row.setValue("total", (qreal)num / allProcessedTime); |
114 | dataset.insertRow(row); | 117 | dataset.insertRow(row); |
115 | HAWD::Formatter::print(dataset); | 118 | HAWD::Formatter::print(dataset); |
116 | |||
117 | auto diskUsage = DummyResource::diskUsage("sink.dummy.instance1"); | ||
118 | qDebug() << "Database size [kb]: " << diskUsage / 1024; | ||
119 | |||
120 | // Print memory layout, RSS is what is in memory | ||
121 | // std::system("exec pmap -x \"$PPID\""); | ||
122 | } | 119 | } |
123 | 120 | ||
124 | void testQueryByUid() | 121 | void testQueryByUid() |
@@ -133,7 +130,7 @@ private slots: | |||
133 | 130 | ||
134 | query.filter("uid", Sink::Query::Comparator("testuid")); | 131 | query.filter("uid", Sink::Query::Comparator("testuid")); |
135 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); | 132 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); |
136 | QTRY_COMPARE(model->rowCount(QModelIndex()), num); | 133 | QUICK_TRY_VERIFY(model->rowCount(QModelIndex()) == num); |
137 | } | 134 | } |
138 | auto queryTime = time.elapsed(); | 135 | auto queryTime = time.elapsed(); |
139 | 136 | ||
@@ -145,83 +142,6 @@ private slots: | |||
145 | HAWD::Formatter::print(dataset); | 142 | HAWD::Formatter::print(dataset); |
146 | } | 143 | } |
147 | 144 | ||
148 | void testWriteInProcess() | ||
149 | { | ||
150 | VERIFYEXEC(Sink::Store::removeDataFromDisk("sink.dummy.instance1")); | ||
151 | QTime time; | ||
152 | time.start(); | ||
153 | |||
154 | DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")}); | ||
155 | |||
156 | flatbuffers::FlatBufferBuilder eventFbb; | ||
157 | eventFbb.Clear(); | ||
158 | { | ||
159 | auto summary = eventFbb.CreateString("summary"); | ||
160 | Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
161 | eventBuilder.add_summary(summary); | ||
162 | auto eventLocation = eventBuilder.Finish(); | ||
163 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
164 | } | ||
165 | |||
166 | flatbuffers::FlatBufferBuilder localFbb; | ||
167 | { | ||
168 | auto uid = localFbb.CreateString("testuid"); | ||
169 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
170 | localBuilder.add_uid(uid); | ||
171 | auto location = localBuilder.Finish(); | ||
172 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
173 | } | ||
174 | |||
175 | flatbuffers::FlatBufferBuilder entityFbb; | ||
176 | Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
177 | |||
178 | flatbuffers::FlatBufferBuilder fbb; | ||
179 | auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data()); | ||
180 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
181 | Sink::Commands::CreateEntityBuilder builder(fbb); | ||
182 | builder.add_domainType(type); | ||
183 | builder.add_delta(delta); | ||
184 | auto location = builder.Finish(); | ||
185 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
186 | |||
187 | const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
188 | |||
189 | for (int i = 0; i < num; i++) { | ||
190 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
191 | } | ||
192 | auto appendTime = time.elapsed(); | ||
193 | |||
194 | // Wait until all messages have been processed | ||
195 | resource.processAllMessages().exec().waitForFinished(); | ||
196 | |||
197 | auto allProcessedTime = time.elapsed(); | ||
198 | |||
199 | |||
200 | // Print memory layout, RSS is what is in memory | ||
201 | // std::system("exec pmap -x \"$PPID\""); | ||
202 | } | ||
203 | |||
204 | void testCreateCommand() | ||
205 | { | ||
206 | Sink::ApplicationDomain::Event event; | ||
207 | |||
208 | QBENCHMARK { | ||
209 | auto mFactory = new DummyEventAdaptorFactory; | ||
210 | static flatbuffers::FlatBufferBuilder entityFbb; | ||
211 | entityFbb.Clear(); | ||
212 | mFactory->createBuffer(event, entityFbb); | ||
213 | |||
214 | static flatbuffers::FlatBufferBuilder fbb; | ||
215 | fbb.Clear(); | ||
216 | // This is the resource buffer type and not the domain type | ||
217 | auto entityId = fbb.CreateString(""); | ||
218 | auto type = fbb.CreateString("event"); | ||
219 | // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
220 | auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
221 | auto location = Sink::Commands::CreateCreateEntity(fbb, entityId, type, delta); | ||
222 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
223 | } | ||
224 | } | ||
225 | 145 | ||
226 | // This allows to run individual parts without doing a cleanup, but still cleaning up normally | 146 | // This allows to run individual parts without doing a cleanup, but still cleaning up normally |
227 | void testCleanupForCompleteTest() | 147 | void testCleanupForCompleteTest() |
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 17df160..28e8337 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "test.h" | 14 | #include "test.h" |
15 | #include "testutils.h" | 15 | #include "testutils.h" |
16 | #include "adaptorfactoryregistry.h" | 16 | #include "adaptorfactoryregistry.h" |
17 | #include "notifier.h" | ||
17 | 18 | ||
18 | using namespace Sink; | 19 | using namespace Sink; |
19 | using namespace Sink::ApplicationDomain; | 20 | using namespace Sink::ApplicationDomain; |
@@ -275,6 +276,37 @@ private slots: | |||
275 | QTRY_COMPARE(model->rowCount(QModelIndex()), 0); | 276 | QTRY_COMPARE(model->rowCount(QModelIndex()), 0); |
276 | } | 277 | } |
277 | } | 278 | } |
279 | |||
280 | void testCommandResponsiveness() | ||
281 | { | ||
282 | // Test responsiveness including starting the process. | ||
283 | VERIFYEXEC(Sink::Store::removeDataFromDisk("sink.dummy.instance1")); | ||
284 | |||
285 | QTime time; | ||
286 | time.start(); | ||
287 | |||
288 | Sink::ApplicationDomain::Event event("sink.dummy.instance1"); | ||
289 | event.setProperty("uid", "testuid"); | ||
290 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | ||
291 | event.setProperty("summary", "summaryValue"); | ||
292 | |||
293 | auto notifier = QSharedPointer<Sink::Notifier>::create("sink.dummy.instance1", "sink.dummy"); | ||
294 | bool gotNotification = false; | ||
295 | int duration = 0; | ||
296 | notifier->registerHandler([&gotNotification, &duration, &time](const Sink::Notification ¬ification) { | ||
297 | if (notification.type == Sink::Notification::RevisionUpdate) { | ||
298 | gotNotification = true; | ||
299 | duration = time.elapsed(); | ||
300 | } | ||
301 | }); | ||
302 | |||
303 | Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec(); | ||
304 | // Wait for notification | ||
305 | QUICK_TRY_VERIFY(gotNotification); | ||
306 | |||
307 | QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); | ||
308 | VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); | ||
309 | } | ||
278 | }; | 310 | }; |
279 | 311 | ||
280 | QTEST_MAIN(DummyResourceTest) | 312 | QTEST_MAIN(DummyResourceTest) |
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index ff61e81..4d67dca 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp | |||
@@ -103,7 +103,7 @@ class MailQueryBenchmark : public QObject | |||
103 | bool done = false; | 103 | bool done = false; |
104 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); | 104 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); |
105 | emitter->fetch(Mail::Ptr()); | 105 | emitter->fetch(Mail::Ptr()); |
106 | QUICK_TRY_VERIFY(!done); | 106 | QUICK_TRY_VERIFY(done); |
107 | Q_ASSERT(list.size() == expectedSize); | 107 | Q_ASSERT(list.size() == expectedSize); |
108 | 108 | ||
109 | const auto elapsed = time.elapsed(); | 109 | const auto elapsed = time.elapsed(); |
@@ -217,7 +217,7 @@ private slots: | |||
217 | bool done = false; | 217 | bool done = false; |
218 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); | 218 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); |
219 | emitter->fetch(Mail::Ptr()); | 219 | emitter->fetch(Mail::Ptr()); |
220 | QUICK_TRY_VERIFY(!done); | 220 | QUICK_TRY_VERIFY(done); |
221 | QCOMPARE(added.size(), expectedSize); | 221 | QCOMPARE(added.size(), expectedSize); |
222 | 222 | ||
223 | auto initialQueryTime = time.elapsed(); | 223 | auto initialQueryTime = time.elapsed(); |
@@ -230,9 +230,9 @@ private slots: | |||
230 | context.mResourceAccess->revisionChanged(1000 + i * 100); | 230 | context.mResourceAccess->revisionChanged(1000 + i * 100); |
231 | } | 231 | } |
232 | //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails | 232 | //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails |
233 | QUICK_TRY_VERIFY(added.count() != 200); | 233 | QUICK_TRY_VERIFY(added.count() == 200); |
234 | //We get one modification per thread from the first 100 (1000 mails / 10 folders), everything else is optimized away because we ignore repeated updates to the same thread. | 234 | //We get one modification per thread from the first 100 (1000 mails / 10 folders), everything else is optimized away because we ignore repeated updates to the same thread. |
235 | QUICK_TRY_VERIFY(modified.count() != 100); | 235 | QUICK_TRY_VERIFY(modified.count() == 100); |
236 | auto incrementalQueryTime = time.elapsed(); | 236 | auto incrementalQueryTime = time.elapsed(); |
237 | std::cout << "Incremental query took " << incrementalQueryTime << std::endl; | 237 | std::cout << "Incremental query took " << incrementalQueryTime << std::endl; |
238 | std::cout << "added " << added.count() << std::endl; | 238 | std::cout << "added " << added.count() << std::endl; |
diff --git a/tests/testutils.h b/tests/testutils.h index 6e935f3..f464e76 100644 --- a/tests/testutils.h +++ b/tests/testutils.h | |||
@@ -46,10 +46,15 @@ do {\ | |||
46 | return;\ | 46 | return;\ |
47 | } while (0) | 47 | } while (0) |
48 | 48 | ||
49 | //qWait(1) seems to simply skip waiting at all. | ||
49 | #define QUICK_TRY_VERIFY(statement) \ | 50 | #define QUICK_TRY_VERIFY(statement) \ |
50 | do {\ | 51 | do {\ |
51 | static int timeout = 5000; \ | 52 | static int timeout = 2500; \ |
52 | for (int i = 0; i < timeout && #statement; i++) { \ | 53 | int i = 0; \ |
53 | QTest::qWait(1); \ | 54 | for (; i < timeout && !(statement); i++) { \ |
55 | QTest::qWait(2); \ | ||
56 | } \ | ||
57 | if (i >= timeout) { \ | ||
58 | qWarning() << "Timeout during QUICK_TRY_VERIFY"; \ | ||
54 | } \ | 59 | } \ |
55 | } while (0) | 60 | } while (0) |