summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_selftest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-02-13 16:25:56 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-02-13 16:25:56 +0100
commit2856a783f0c935d9ef635f5a8dd43f74bda38299 (patch)
tree699d1ff20af3cff96ae959cccf06490f246005ff /sinksh/syntax_modules/sink_selftest.cpp
parent8035957cf586a7349813934b43c925c39ae76fd0 (diff)
downloadsink-2856a783f0c935d9ef635f5a8dd43f74bda38299.tar.gz
sink-2856a783f0c935d9ef635f5a8dd43f74bda38299.zip
A sinksh module geared towards self-testing and stress testing.
Diffstat (limited to 'sinksh/syntax_modules/sink_selftest.cpp')
-rw-r--r--sinksh/syntax_modules/sink_selftest.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/sinksh/syntax_modules/sink_selftest.cpp b/sinksh/syntax_modules/sink_selftest.cpp
new file mode 100644
index 0000000..21dfbff
--- /dev/null
+++ b/sinksh/syntax_modules/sink_selftest.cpp
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
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
20#include <QCoreApplication>
21#include <QDebug>
22#include <QObject> // tr()
23#include <QModelIndex>
24#include <QTime>
25
26#include "common/resource.h"
27#include "common/storage.h"
28#include "common/resourceconfig.h"
29#include "common/log.h"
30#include "common/storage.h"
31#include "common/definitions.h"
32#include "common/store.h"
33#include "common/propertyparser.h"
34
35#include "sinksh_utils.h"
36#include "state.h"
37#include "syntaxtree.h"
38
39namespace SinkSelfTest
40{
41
42bool selfTest(const QStringList &args_, State &state)
43{
44 if (args_.isEmpty()) {
45 state.printError(QObject::tr("Options: $type [--resource $resource] stresstest"));
46 return false;
47 }
48
49 auto options = SyntaxTree::parseOptions(args_);
50 if (options.positionalArguments.contains("stresstest")) {
51 auto resource = SinkshUtils::parseUid(options.options.value("resource").first().toUtf8());
52 qWarning() << "Stresstest on resource: " << resource;
53 Sink::Query query;
54 query.resourceFilter(resource);
55 query.limit(100);
56
57 auto models = QSharedPointer<QList<QSharedPointer<QAbstractItemModel>>>::create();
58 for (int i = 0; i < 50; i++) {
59 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
60 *models << model;
61 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [models, model, &state](const QModelIndex &start, const QModelIndex &end, const QVector<int> &roles) {
62 if (roles.contains(Sink::Store::ChildrenFetchedRole)) {
63 models->removeAll(model);
64 qWarning() << "Model complete: " << models->count();
65 if (models->isEmpty()) {
66 state.commandFinished();
67 }
68 }
69 });
70 }
71 return true;
72 }
73 return false;
74}
75
76Syntax::List syntax()
77{
78 Syntax syntax("selftest", QObject::tr("Selftext."), &SinkSelfTest::selfTest, Syntax::EventDriven);
79 return Syntax::List() << syntax;
80}
81
82REGISTER_SYNTAX(SinkSelfTest)
83
84}