TaskTree: Fix withCancel test flakiness (2nd try)

Ensure the created task lasts long enough so that the 2 queued
signals with 0 timeout are delivered before the task finishes.

In case of a very slow machine, or when running valgrind memory analyzer,
it may happen that the time elapsed since queueing a call, until
the call is handled, may be longer than 1ms. In this case, the
task's done handler is invoked before the cancel signal is delivered.

To ensure that it doesn't happen, make the task last for very long time.

Amends 30d3f8ceb8

Change-Id: Icdeb48df6ed385eab86e0447baca128ccf50de37
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-11 09:27:05 +01:00
parent e65dbc1c10
commit 9fcb8e8c79

View File

@@ -17,6 +17,8 @@ using namespace std::chrono_literals;
using TaskObject = milliseconds;
using TestTask = TimeoutTask;
constexpr milliseconds s_endlessTime = 1000000s;
namespace PrintableEnums {
Q_NAMESPACE
@@ -347,17 +349,6 @@ void tst_Tasking::runtimeCheck()
}
}
class Tick : public QObject
{
Q_OBJECT
public:
Tick(const milliseconds &interval) { QTimer::singleShot(interval, this, &Tick::tick); }
signals:
void tick();
};
class TickAndDone : public QObject
{
Q_OBJECT
@@ -3171,7 +3162,7 @@ void tst_Tasking::testTree_data()
// This test ensures the task done handlers are invoked in a different order
// than the corresponding setup handlers.
const QList<milliseconds> tasks { 1000000ms, 0ms };
const QList<milliseconds> tasks { s_endlessTime, 0ms };
const LoopList iterator(tasks);
const auto onSetup = [storage, iterator](TaskObject &taskObject) {
@@ -3790,25 +3781,28 @@ void tst_Tasking::testTree_data()
{
// withCancel / withAccept
const Storage<std::unique_ptr<Tick>> tickStorage;
const Storage<std::unique_ptr<QTimer>> tickStorage;
const auto onSetup = [tickStorage](milliseconds timeout) {
return [tickStorage, timeout] { tickStorage->reset(new Tick(timeout)); };
return [tickStorage, timeout] {
tickStorage->reset(new QTimer);
tickStorage->get()->start(timeout);
};
};
const auto onTickSetup = [tickStorage] {
return std::make_pair(tickStorage->get(), &Tick::tick);
return std::make_pair(tickStorage->get(), &QTimer::timeout);
};
const Group cancelRecipe {
storage,
tickStorage,
onGroupSetup(onSetup(0ms)),
onGroupSetup(onSetup(0ms)), // 1st queued call
Group {
groupSetup(1),
createSuccessTask(2, 1ms),
createSuccessTask(2, s_endlessTime),
groupDone(1)
}.withCancel(onTickSetup)
}.withCancel(onTickSetup) // 2nd queued call
};
const Log cancelLog {