TaskTree: Don't call storage done handlers from TaskTree's d'tor

Change-Id: Ie2b04d433be3452f9e668efd3341dedfcb154290
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-02-21 12:05:18 +01:00
parent 97b97825ed
commit 8eaf73700e
2 changed files with 30 additions and 6 deletions

View File

@@ -175,6 +175,7 @@ public:
~RuntimeData();
static QList<int> createStorages(const TaskContainer::ConstData &constData);
void callStorageDoneHandlers();
bool updateSuccessBit(bool success);
int currentLimit() const;
@@ -384,6 +385,15 @@ QList<int> TaskContainer::RuntimeData::createStorages(const TaskContainer::Const
return storageIdList;
}
void TaskContainer::RuntimeData::callStorageDoneHandlers()
{
for (int i = m_constData.m_storageList.size() - 1; i >= 0; --i) { // iterate in reverse order
const TreeStorageBase storage = m_constData.m_storageList[i];
const int storageId = m_storageIdList.value(i);
m_constData.m_taskTreePrivate->callDoneHandler(storage, storageId);
}
}
TaskContainer::RuntimeData::RuntimeData(const ConstData &constData)
: m_constData(constData)
, m_storageIdList(createStorages(constData))
@@ -397,7 +407,6 @@ TaskContainer::RuntimeData::~RuntimeData()
for (int i = m_constData.m_storageList.size() - 1; i >= 0; --i) { // iterate in reverse order
const TreeStorageBase storage = m_constData.m_storageList[i];
const int storageId = m_storageIdList.value(i);
m_constData.m_taskTreePrivate->callDoneHandler(storage, storageId);
storage.deleteStorage(storageId);
}
}
@@ -527,6 +536,7 @@ void TaskContainer::invokeEndHandler()
invokeHandler(this, groupHandler.m_doneHandler);
else if (!m_runtimeData->m_successBit && groupHandler.m_errorHandler)
invokeHandler(this, groupHandler.m_errorHandler);
m_runtimeData->callStorageDoneHandlers();
m_runtimeData.reset();
}

View File

@@ -1054,26 +1054,40 @@ void tst_TaskTree::storageOperators()
}
// This test checks whether a running task tree may be safely destructed.
// It also checks whether destructor of task tree deletes properly the storage created
// while starting the task tree.
// It also checks whether the destructor of a task tree deletes properly the storage created
// while starting the task tree. When running task tree is destructed, the storage done
// handler shouldn't be invoked.
void tst_TaskTree::storageDestructor()
{
bool setupCalled = false;
const auto setupHandler = [&setupCalled](CustomStorage *) {
setupCalled = true;
};
bool doneCalled = false;
const auto doneHandler = [&doneCalled](CustomStorage *) {
doneCalled = true;
};
QCOMPARE(CustomStorage::instanceCount(), 0);
{
TreeStorage<CustomStorage> storage;
const auto setupProcess = [testAppPath = m_testAppPath](QtcProcess &process) {
process.setCommand(CommandLine(testAppPath, {"-sleep", "1000"}));
};
const Group root {
Storage(TreeStorage<CustomStorage>()),
Storage(storage),
Process(setupProcess)
};
TaskTree processTree(root);
TaskTree taskTree(root);
QCOMPARE(CustomStorage::instanceCount(), 0);
processTree.start();
taskTree.onStorageSetup(storage, setupHandler);
taskTree.onStorageDone(storage, doneHandler);
taskTree.start();
QCOMPARE(CustomStorage::instanceCount(), 1);
}
QCOMPARE(CustomStorage::instanceCount(), 0);
QVERIFY(setupCalled);
QVERIFY(!doneCalled);
}
QTEST_GUILESS_MAIN(tst_TaskTree)