2022-10-12 14:30:24 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-10-12 14:30:24 +02:00
|
|
|
|
|
|
|
|
#include <app/app_version.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/launcherinterface.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
#include <utils/singleton.h>
|
|
|
|
|
#include <utils/temporarydirectory.h>
|
|
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
2022-12-04 08:31:14 +01:00
|
|
|
using namespace Utils::Tasking;
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
enum class Handler {
|
|
|
|
|
Setup,
|
|
|
|
|
Done,
|
|
|
|
|
Error,
|
|
|
|
|
GroupSetup,
|
|
|
|
|
GroupDone,
|
|
|
|
|
GroupError
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using Log = QList<QPair<int, Handler>>;
|
|
|
|
|
|
|
|
|
|
struct CustomStorage
|
|
|
|
|
{
|
|
|
|
|
CustomStorage() { ++s_count; }
|
|
|
|
|
~CustomStorage() { --s_count; }
|
|
|
|
|
Log m_log;
|
|
|
|
|
static int instanceCount() { return s_count; }
|
|
|
|
|
private:
|
|
|
|
|
static int s_count;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int CustomStorage::s_count = 0;
|
|
|
|
|
static const char s_processIdProperty[] = "__processId";
|
|
|
|
|
|
|
|
|
|
enum class OnStart { Running, NotRunning };
|
|
|
|
|
enum class OnDone { Success, Failure };
|
|
|
|
|
|
|
|
|
|
struct TestData {
|
|
|
|
|
TreeStorage<CustomStorage> storage;
|
|
|
|
|
Group root;
|
|
|
|
|
Log expectedLog;
|
|
|
|
|
int taskCount = 0;
|
|
|
|
|
OnStart onStart = OnStart::Running;
|
|
|
|
|
OnDone onDone = OnDone::Success;
|
|
|
|
|
};
|
|
|
|
|
|
2022-10-12 14:30:24 +02:00
|
|
|
class tst_TaskTree : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
|
|
void validConstructs(); // compile test
|
|
|
|
|
void processTree_data();
|
|
|
|
|
void processTree();
|
2022-12-04 08:31:14 +01:00
|
|
|
void storageOperators();
|
2022-11-22 15:21:45 +01:00
|
|
|
void storageDestructor();
|
2022-10-12 14:30:24 +02:00
|
|
|
|
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FilePath m_testAppPath;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::initTestCase()
|
|
|
|
|
{
|
2023-01-26 19:06:02 +01:00
|
|
|
TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/"
|
|
|
|
|
+ Core::Constants::IDE_CASED_ID + "-XXXXXX");
|
2022-10-12 14:30:24 +02:00
|
|
|
const QString libExecPath(qApp->applicationDirPath() + '/'
|
|
|
|
|
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
|
|
|
|
LauncherInterface::setPathToLauncher(libExecPath);
|
|
|
|
|
m_testAppPath = FilePath::fromString(QLatin1String(TESTAPP_PATH)
|
|
|
|
|
+ QLatin1String("/testapp")).withExecutableSuffix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::cleanupTestCase()
|
|
|
|
|
{
|
2023-01-26 19:06:02 +01:00
|
|
|
Singleton::deleteAll();
|
2022-10-12 14:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::validConstructs()
|
|
|
|
|
{
|
|
|
|
|
const Group process {
|
|
|
|
|
parallel,
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {}),
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {}),
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Group group1 {
|
|
|
|
|
process
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Group group2 {
|
|
|
|
|
parallel,
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {}),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {}),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process([](QtcProcess &) {}, [](const QtcProcess &) {}),
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone([] {})
|
2022-10-12 14:30:24 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
process,
|
|
|
|
|
OnGroupDone([] {}),
|
|
|
|
|
OnGroupError([] {})
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::processTree_data()
|
|
|
|
|
{
|
2023-01-26 19:06:02 +01:00
|
|
|
QTest::addColumn<TestData>("testData");
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2022-12-05 18:08:48 +01:00
|
|
|
TreeStorage<CustomStorage> storage;
|
|
|
|
|
|
|
|
|
|
const auto setupProcessHelper = [storage, testAppPath = m_testAppPath]
|
|
|
|
|
(QtcProcess &process, const QStringList &args, int processId) {
|
|
|
|
|
process.setCommand(CommandLine(testAppPath, args));
|
2022-10-12 14:30:24 +02:00
|
|
|
process.setProperty(s_processIdProperty, processId);
|
2022-12-05 18:08:48 +01:00
|
|
|
storage->m_log.append({processId, Handler::Setup});
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto setupProcess = [setupProcessHelper](int processId) {
|
|
|
|
|
return [=](QtcProcess &process) {
|
|
|
|
|
setupProcessHelper(process, {"-return", "0"}, processId);
|
|
|
|
|
};
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto setupCrashProcess = [setupProcessHelper](int processId) {
|
|
|
|
|
return [=](QtcProcess &process) {
|
|
|
|
|
setupProcessHelper(process, {"-crash"}, processId);
|
|
|
|
|
};
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto setupDynamicProcess = [setupProcessHelper](int processId, TaskAction action) {
|
|
|
|
|
return [=](QtcProcess &process) {
|
|
|
|
|
setupProcessHelper(process, {"-return", "0"}, processId);
|
|
|
|
|
return action;
|
|
|
|
|
};
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2022-12-05 18:08:48 +01:00
|
|
|
const auto readResult = [storage](const QtcProcess &process) {
|
2022-10-12 14:30:24 +02:00
|
|
|
const int processId = process.property(s_processIdProperty).toInt();
|
2022-12-05 18:08:48 +01:00
|
|
|
storage->m_log.append({processId, Handler::Done});
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2022-12-05 18:08:48 +01:00
|
|
|
const auto readError = [storage](const QtcProcess &process) {
|
2022-10-12 14:30:24 +02:00
|
|
|
const int processId = process.property(s_processIdProperty).toInt();
|
2022-12-05 18:08:48 +01:00
|
|
|
storage->m_log.append({processId, Handler::Error});
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto groupSetup = [storage](int groupId) {
|
|
|
|
|
return [=] { storage->m_log.append({groupId, Handler::GroupSetup}); };
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto groupDone = [storage](int groupId) {
|
|
|
|
|
return [=] { storage->m_log.append({groupId, Handler::GroupDone}); };
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto groupError = [storage](int groupId) {
|
|
|
|
|
return [=] { storage->m_log.append({groupId, Handler::GroupError}); };
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
|
|
|
|
|
const auto constructSimpleSequence = [=](const Workflow &policy) {
|
|
|
|
|
return Group {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
policy,
|
|
|
|
|
Process(setupProcess(1), readResult),
|
|
|
|
|
Process(setupCrashProcess(2), readResult, readError),
|
|
|
|
|
Process(setupProcess(3), readResult),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const auto constructDynamicHierarchy = [=](TaskAction taskAction) {
|
|
|
|
|
return Group {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
Process(setupProcess(1), readResult)
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup([=] { return taskAction; }),
|
|
|
|
|
Process(setupProcess(2), readResult),
|
|
|
|
|
Process(setupProcess(3), readResult),
|
|
|
|
|
Process(setupProcess(4), readResult)
|
|
|
|
|
},
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
2023-01-09 20:52:12 +01:00
|
|
|
};
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
{
|
2023-01-31 19:33:22 +01:00
|
|
|
const Group root1 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
|
|
|
|
const Group root2 {
|
2023-01-26 19:06:02 +01:00
|
|
|
Storage(storage),
|
2023-01-31 19:33:22 +01:00
|
|
|
OnGroupSetup([] { return TaskAction::Continue; }),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
|
|
|
|
const Group root3 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
OnGroupSetup([] { return TaskAction::StopWithDone; }),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
|
|
|
|
const Group root4 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
OnGroupSetup([] { return TaskAction::StopWithError; }),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
2023-01-26 19:06:02 +01:00
|
|
|
};
|
2023-01-31 19:33:22 +01:00
|
|
|
const Log logDone {{0, Handler::GroupDone}};
|
|
|
|
|
const Log logError {{0, Handler::GroupError}};
|
2023-01-26 19:06:02 +01:00
|
|
|
QTest::newRow("Empty")
|
2023-01-31 19:33:22 +01:00
|
|
|
<< TestData{storage, root1, logDone, 0, OnStart::NotRunning, OnDone::Success};
|
|
|
|
|
QTest::newRow("EmptyContinue")
|
|
|
|
|
<< TestData{storage, root2, logDone, 0, OnStart::NotRunning, OnDone::Success};
|
|
|
|
|
QTest::newRow("EmptyDone")
|
|
|
|
|
<< TestData{storage, root3, logDone, 0, OnStart::NotRunning, OnDone::Success};
|
|
|
|
|
QTest::newRow("EmptyError")
|
|
|
|
|
<< TestData{storage, root4, logError, 0, OnStart::NotRunning, OnDone::Failure};
|
2023-01-26 19:06:02 +01:00
|
|
|
}
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::StopWithDone), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::StopWithDone), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {{1, Handler::Setup}, {2, Handler::Setup}};
|
|
|
|
|
QTest::newRow("DynamicTaskDone")
|
|
|
|
|
<< TestData{storage, root, log, 2, OnStart::NotRunning, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::StopWithError), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::StopWithError), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {{1, Handler::Setup}};
|
|
|
|
|
QTest::newRow("DynamicTaskError")
|
|
|
|
|
<< TestData{storage, root, log, 2, OnStart::NotRunning, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::StopWithError), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(4, TaskAction::Continue), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Done},
|
|
|
|
|
{3, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicMixed")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
parallel,
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::StopWithError), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(4, TaskAction::Continue), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{1, Handler::Error},
|
|
|
|
|
{2, Handler::Error}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicParallel")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::NotRunning, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
parallel,
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Group {
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::StopWithError), readResult, readError)
|
|
|
|
|
},
|
|
|
|
|
Process(setupDynamicProcess(4, TaskAction::Continue), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{1, Handler::Error},
|
|
|
|
|
{2, Handler::Error}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicParallelGroup")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::NotRunning, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
parallel,
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupDynamicProcess(1, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Process(setupDynamicProcess(2, TaskAction::Continue), readResult, readError),
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup([storage] {
|
|
|
|
|
storage->m_log.append({0, Handler::GroupSetup});
|
|
|
|
|
return TaskAction::StopWithError;
|
|
|
|
|
}),
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::Continue), readResult, readError)
|
|
|
|
|
},
|
|
|
|
|
Process(setupDynamicProcess(4, TaskAction::Continue), readResult, readError)
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{0, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Error},
|
|
|
|
|
{2, Handler::Error}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicParallelGroupSetup")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::NotRunning, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
2022-10-12 14:30:24 +02:00
|
|
|
Group {
|
|
|
|
|
Group {
|
|
|
|
|
Group {
|
|
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Group {
|
|
|
|
|
Process(setupProcess(5), readResult, readError),
|
|
|
|
|
OnGroupSetup(groupSetup(5)),
|
|
|
|
|
OnGroupDone(groupDone(5))
|
|
|
|
|
},
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
OnGroupDone(groupDone(4))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
OnGroupDone(groupDone(3))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
OnGroupDone(groupDone(2))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
OnGroupDone(groupDone(1))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone(groupDone(0))
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{4, Handler::GroupSetup},
|
|
|
|
|
{5, Handler::GroupSetup},
|
|
|
|
|
{5, Handler::Setup},
|
|
|
|
|
{5, Handler::Done},
|
|
|
|
|
{5, Handler::GroupDone},
|
|
|
|
|
{4, Handler::GroupDone},
|
|
|
|
|
{3, Handler::GroupDone},
|
|
|
|
|
{2, Handler::GroupDone},
|
|
|
|
|
{1, Handler::GroupDone},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("Nested")
|
|
|
|
|
<< TestData{storage, root, log, 1, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const auto readResultAnonymous = [=](const QtcProcess &) {
|
|
|
|
|
storage->m_log.append({0, Handler::Done});
|
|
|
|
|
};
|
|
|
|
|
const Group root {
|
2022-12-05 18:08:48 +01:00
|
|
|
Storage(storage),
|
2023-01-26 19:06:02 +01:00
|
|
|
parallel,
|
|
|
|
|
Process(setupProcess(1), readResultAnonymous),
|
|
|
|
|
Process(setupProcess(2), readResultAnonymous),
|
|
|
|
|
Process(setupProcess(3), readResultAnonymous),
|
|
|
|
|
Process(setupProcess(4), readResultAnonymous),
|
|
|
|
|
Process(setupProcess(5), readResultAnonymous),
|
|
|
|
|
OnGroupDone(groupDone(0))
|
2022-11-16 09:06:32 +01:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup}, // Setup order is determined in parallel mode
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{5, Handler::Setup},
|
|
|
|
|
{0, Handler::Done}, // Done order isn't determined in parallel mode
|
|
|
|
|
{0, Handler::Done},
|
|
|
|
|
{0, Handler::Done},
|
|
|
|
|
{0, Handler::Done},
|
|
|
|
|
{0, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
2022-12-05 18:08:48 +01:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
QTest::newRow("Parallel")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto setupSubTree = [=](TaskTree &taskTree) {
|
|
|
|
|
const Group nestedRoot {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupProcess(2), readResult),
|
|
|
|
|
Process(setupProcess(3), readResult),
|
|
|
|
|
Process(setupProcess(4), readResult)
|
|
|
|
|
};
|
|
|
|
|
taskTree.setupRoot(nestedRoot);
|
|
|
|
|
CustomStorage *activeStorage = storage.activeStorage();
|
|
|
|
|
auto collectSubLog = [activeStorage](CustomStorage *subTreeStorage){
|
|
|
|
|
activeStorage->m_log += subTreeStorage->m_log;
|
|
|
|
|
};
|
|
|
|
|
taskTree.onStorageDone(storage, collectSubLog);
|
|
|
|
|
};
|
|
|
|
|
const Group root1 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupProcess(1), readResult),
|
|
|
|
|
Process(setupProcess(2), readResult),
|
|
|
|
|
Process(setupProcess(3), readResult),
|
|
|
|
|
Process(setupProcess(4), readResult),
|
|
|
|
|
Process(setupProcess(5), readResult),
|
|
|
|
|
OnGroupDone(groupDone(0))
|
|
|
|
|
};
|
|
|
|
|
const Group root2 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group { Process(setupProcess(1), readResult) },
|
|
|
|
|
Group { Process(setupProcess(2), readResult) },
|
|
|
|
|
Group { Process(setupProcess(3), readResult) },
|
|
|
|
|
Group { Process(setupProcess(4), readResult) },
|
|
|
|
|
Group { Process(setupProcess(5), readResult) },
|
|
|
|
|
OnGroupDone(groupDone(0))
|
|
|
|
|
};
|
|
|
|
|
const Group root3 {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Process(setupProcess(1), readResult),
|
|
|
|
|
Tree(setupSubTree),
|
|
|
|
|
Process(setupProcess(5), readResult),
|
|
|
|
|
OnGroupDone(groupDone(0))
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Done},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Done},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{4, Handler::Done},
|
|
|
|
|
{5, Handler::Setup},
|
|
|
|
|
{5, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("Sequential")
|
|
|
|
|
<< TestData{storage, root1, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
QTest::newRow("SequentialEncapsulated")
|
|
|
|
|
<< TestData{storage, root2, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
QTest::newRow("SequentialSubTree") // We don't inspect subtrees, so taskCount is 3, not 5.
|
|
|
|
|
<< TestData{storage, root3, log, 3, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
2022-10-12 14:30:24 +02:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Process(setupProcess(1), readResult),
|
2022-10-12 14:30:24 +02:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Process(setupProcess(2), readResult),
|
2022-10-12 14:30:24 +02:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Process(setupProcess(3), readResult),
|
2022-10-12 14:30:24 +02:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Process(setupProcess(4), readResult),
|
|
|
|
|
Group {
|
|
|
|
|
Process(setupProcess(5), readResult),
|
|
|
|
|
OnGroupDone(groupDone(5))
|
|
|
|
|
},
|
|
|
|
|
OnGroupDone(groupDone(4))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone(groupDone(3))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone(groupDone(2))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone(groupDone(1))
|
2022-10-12 14:30:24 +02:00
|
|
|
},
|
2023-01-26 19:06:02 +01:00
|
|
|
OnGroupDone(groupDone(0))
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Done},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Done},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{4, Handler::Done},
|
|
|
|
|
{5, Handler::Setup},
|
|
|
|
|
{5, Handler::Done},
|
|
|
|
|
{5, Handler::GroupDone},
|
|
|
|
|
{4, Handler::GroupDone},
|
|
|
|
|
{3, Handler::GroupDone},
|
|
|
|
|
{2, Handler::GroupDone},
|
|
|
|
|
{1, Handler::GroupDone},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("SequentialNested")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
{
|
|
|
|
|
const Group root {
|
2022-12-05 18:08:48 +01:00
|
|
|
Storage(storage),
|
2023-01-26 19:06:02 +01:00
|
|
|
Process(setupProcess(1), readResult),
|
|
|
|
|
Process(setupProcess(2), readResult),
|
|
|
|
|
Process(setupCrashProcess(3), readResult, readError),
|
|
|
|
|
Process(setupProcess(4), readResult),
|
|
|
|
|
Process(setupProcess(5), readResult),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
2022-10-12 14:30:24 +02:00
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Done},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Error},
|
|
|
|
|
{0, Handler::GroupError}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("SequentialError")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
{
|
|
|
|
|
const Group root = constructSimpleSequence(stopOnError);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Error},
|
|
|
|
|
{0, Handler::GroupError}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("StopOnError")
|
|
|
|
|
<< TestData{storage, root, log, 3, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructSimpleSequence(continueOnError);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Error},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Done},
|
|
|
|
|
{0, Handler::GroupError}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("ContinueOnError")
|
|
|
|
|
<< TestData{storage, root, log, 3, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructSimpleSequence(stopOnDone);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("StopOnDone")
|
|
|
|
|
<< TestData{storage, root, log, 3, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructSimpleSequence(continueOnDone);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Error},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("ContinueOnDone")
|
|
|
|
|
<< TestData{storage, root, log, 3, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(storage),
|
|
|
|
|
optional,
|
|
|
|
|
Process(setupCrashProcess(1), readResult, readError),
|
|
|
|
|
Process(setupCrashProcess(2), readResult, readError),
|
|
|
|
|
OnGroupDone(groupDone(0)),
|
|
|
|
|
OnGroupError(groupError(0))
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Error},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Error},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("Optional")
|
|
|
|
|
<< TestData{storage, root, log, 2, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructDynamicHierarchy(TaskAction::StopWithDone);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicSetupDone")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructDynamicHierarchy(TaskAction::StopWithError);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{0, Handler::GroupError}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicSetupError")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root = constructDynamicHierarchy(TaskAction::Continue);
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{1, Handler::Done},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{2, Handler::Done},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{3, Handler::Done},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{4, Handler::Done},
|
|
|
|
|
{0, Handler::GroupDone}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DynamicSetupContinue")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 13:36:44 +01:00
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Process(setupProcess(1))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Process(setupProcess(2))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Process(setupProcess(3))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Process(setupProcess(4))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{4, Handler::GroupSetup},
|
|
|
|
|
{4, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("NestedParallel")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Process(setupProcess(1))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Process(setupProcess(2))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::StopWithDone))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Process(setupProcess(4))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(5)),
|
|
|
|
|
Process(setupProcess(5))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{4, Handler::GroupSetup},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{5, Handler::GroupSetup},
|
|
|
|
|
{5, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("NestedParallelDone")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Process(setupProcess(1))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Process(setupProcess(2))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Process(setupDynamicProcess(3, TaskAction::StopWithError))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Process(setupProcess(4))
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
OnGroupSetup(groupSetup(5)),
|
|
|
|
|
Process(setupProcess(5))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("NestedParallelError")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Failure};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
2022-12-05 18:08:48 +01:00
|
|
|
Storage(storage),
|
2022-11-04 14:08:32 +01:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process(setupProcess(1))
|
|
|
|
|
}
|
2022-11-04 14:08:32 +01:00
|
|
|
},
|
|
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process(setupProcess(2))
|
|
|
|
|
}
|
2022-11-04 14:08:32 +01:00
|
|
|
},
|
2023-01-24 11:56:30 +01:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process(setupProcess(3))
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-01-24 11:56:30 +01:00
|
|
|
Group {
|
2023-01-26 19:06:02 +01:00
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Group {
|
|
|
|
|
parallel,
|
|
|
|
|
Process(setupProcess(4))
|
|
|
|
|
}
|
2023-01-24 11:56:30 +01:00
|
|
|
}
|
2023-01-26 19:06:02 +01:00
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{4, Handler::GroupSetup},
|
|
|
|
|
{4, Handler::Setup}
|
|
|
|
|
};
|
2023-01-27 13:36:44 +01:00
|
|
|
QTest::newRow("DeeplyNestedParallel")
|
|
|
|
|
<< TestData{storage, root, log, 4, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Group { Process(setupProcess(1)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Group { Process(setupProcess(2)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Group { Process(setupDynamicProcess(3, TaskAction::StopWithDone)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Group { Process(setupProcess(4)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(5)),
|
|
|
|
|
Group { Process(setupProcess(5)) }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup},
|
|
|
|
|
{4, Handler::GroupSetup},
|
|
|
|
|
{4, Handler::Setup},
|
|
|
|
|
{5, Handler::GroupSetup},
|
|
|
|
|
{5, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DeeplyNestedParallelDone")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Success};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const Group root {
|
|
|
|
|
ParallelLimit(2),
|
|
|
|
|
Storage(storage),
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(1)),
|
|
|
|
|
Group { Process(setupProcess(1)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(2)),
|
|
|
|
|
Group { Process(setupProcess(2)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(3)),
|
|
|
|
|
Group { Process(setupDynamicProcess(3, TaskAction::StopWithError)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(4)),
|
|
|
|
|
Group { Process(setupProcess(4)) }
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
OnGroupSetup(groupSetup(5)),
|
|
|
|
|
Group { Process(setupProcess(5)) }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Log log {
|
|
|
|
|
{1, Handler::GroupSetup},
|
|
|
|
|
{1, Handler::Setup},
|
|
|
|
|
{2, Handler::GroupSetup},
|
|
|
|
|
{2, Handler::Setup},
|
|
|
|
|
{3, Handler::GroupSetup},
|
|
|
|
|
{3, Handler::Setup}
|
|
|
|
|
};
|
|
|
|
|
QTest::newRow("DeeplyNestedParallelError")
|
|
|
|
|
<< TestData{storage, root, log, 5, OnStart::Running, OnDone::Failure};
|
2023-01-26 19:06:02 +01:00
|
|
|
}
|
2022-10-12 14:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::processTree()
|
|
|
|
|
{
|
2023-01-26 19:06:02 +01:00
|
|
|
QFETCH(TestData, testData);
|
2022-10-12 14:30:24 +02:00
|
|
|
|
|
|
|
|
QEventLoop eventLoop;
|
2023-01-26 19:06:02 +01:00
|
|
|
TaskTree taskTree(testData.root);
|
|
|
|
|
QCOMPARE(taskTree.taskCount(), testData.taskCount);
|
2022-10-12 14:30:24 +02:00
|
|
|
int doneCount = 0;
|
|
|
|
|
int errorCount = 0;
|
2022-12-05 18:08:48 +01:00
|
|
|
connect(&taskTree, &TaskTree::done, this, [&doneCount, &eventLoop] {
|
|
|
|
|
++doneCount;
|
|
|
|
|
eventLoop.quit();
|
|
|
|
|
});
|
|
|
|
|
connect(&taskTree, &TaskTree::errorOccurred, this, [&errorCount, &eventLoop] {
|
|
|
|
|
++errorCount;
|
|
|
|
|
eventLoop.quit();
|
|
|
|
|
});
|
|
|
|
|
Log actualLog;
|
|
|
|
|
auto collectLog = [&actualLog](CustomStorage *storage){
|
|
|
|
|
actualLog = storage->m_log;
|
|
|
|
|
};
|
2023-01-26 19:06:02 +01:00
|
|
|
taskTree.onStorageDone(testData.storage, collectLog);
|
2022-12-05 18:08:48 +01:00
|
|
|
taskTree.start();
|
2023-01-26 19:06:02 +01:00
|
|
|
const bool expectRunning = testData.onStart == OnStart::Running;
|
|
|
|
|
QCOMPARE(taskTree.isRunning(), expectRunning);
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
if (expectRunning) {
|
2022-11-25 12:35:07 +01:00
|
|
|
QTimer timer;
|
|
|
|
|
bool timedOut = false;
|
|
|
|
|
connect(&timer, &QTimer::timeout, &eventLoop, [&eventLoop, &timedOut] {
|
|
|
|
|
timedOut = true;
|
|
|
|
|
eventLoop.quit();
|
|
|
|
|
});
|
2022-12-01 15:50:03 +01:00
|
|
|
timer.setInterval(2000);
|
2022-11-25 12:35:07 +01:00
|
|
|
timer.setSingleShot(true);
|
|
|
|
|
timer.start();
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
QCOMPARE(timedOut, false);
|
2022-12-05 18:08:48 +01:00
|
|
|
QCOMPARE(taskTree.isRunning(), false);
|
2022-11-25 12:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
QCOMPARE(taskTree.progressValue(), testData.taskCount);
|
|
|
|
|
QCOMPARE(actualLog, testData.expectedLog);
|
2022-11-21 15:05:39 +01:00
|
|
|
QCOMPARE(CustomStorage::instanceCount(), 0);
|
2022-10-12 14:30:24 +02:00
|
|
|
|
2023-01-26 19:06:02 +01:00
|
|
|
const bool expectSuccess = testData.onDone == OnDone::Success;
|
|
|
|
|
const int expectedDoneCount = expectSuccess ? 1 : 0;
|
|
|
|
|
const int expectedErrorCount = expectSuccess ? 0 : 1;
|
2022-10-12 14:30:24 +02:00
|
|
|
QCOMPARE(doneCount, expectedDoneCount);
|
|
|
|
|
QCOMPARE(errorCount, expectedErrorCount);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:31:14 +01:00
|
|
|
void tst_TaskTree::storageOperators()
|
2022-11-22 15:21:45 +01:00
|
|
|
{
|
2022-12-04 08:31:14 +01:00
|
|
|
TreeStorageBase storage1 = TreeStorage<CustomStorage>();
|
|
|
|
|
TreeStorageBase storage2 = TreeStorage<CustomStorage>();
|
|
|
|
|
TreeStorageBase storage3 = storage1;
|
2022-11-22 15:21:45 +01:00
|
|
|
|
2022-12-04 08:31:14 +01:00
|
|
|
QVERIFY(storage1 == storage3);
|
|
|
|
|
QVERIFY(storage1 != storage2);
|
|
|
|
|
QVERIFY(storage2 != storage3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TaskTree::storageDestructor()
|
|
|
|
|
{
|
2022-11-22 15:21:45 +01:00
|
|
|
QCOMPARE(CustomStorage::instanceCount(), 0);
|
|
|
|
|
{
|
2022-12-05 18:08:48 +01:00
|
|
|
const auto setupProcess = [testAppPath = m_testAppPath](QtcProcess &process) {
|
|
|
|
|
process.setCommand(CommandLine(testAppPath, {"-sleep", "1"}));
|
2022-11-22 15:21:45 +01:00
|
|
|
};
|
|
|
|
|
const Group root {
|
|
|
|
|
Storage(TreeStorage<CustomStorage>()),
|
|
|
|
|
Process(setupProcess)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TaskTree processTree(root);
|
|
|
|
|
QCOMPARE(CustomStorage::instanceCount(), 0);
|
|
|
|
|
processTree.start();
|
|
|
|
|
QCOMPARE(CustomStorage::instanceCount(), 1);
|
|
|
|
|
}
|
|
|
|
|
QCOMPARE(CustomStorage::instanceCount(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 14:30:24 +02:00
|
|
|
QTEST_GUILESS_MAIN(tst_TaskTree)
|
|
|
|
|
|
|
|
|
|
#include "tst_tasktree.moc"
|