diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-02-24 14:58:09 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-26 08:41:10 +0000 |
commit | d6531d1d143bbcb0a683627b251ad3f8bdf19db9 (patch) | |
tree | e55c2861c409bfea676b541bdfd6477ae9a32fdd /tests/auto | |
parent | b74f77bd6341c98af72bf2ab243c04b37de46cb5 (diff) |
tst_QFuture::continuationsWithContext: fix the flakiness
When attaching a continuation with the default (QtFuture::Launch::Sync)
policy, it will be launched in the same thread where the parent has
been executing, or in the thread where the parent lives, if the
continuation is attached after the parent has already finished. Fixed
the test-case to make sure the continuations are attached while the
parent is still running, so that they can be resolved in the parent's
context.
Fixes: QTBUG-91373
Change-Id: I82b3b0c47b76d121b44bd512659c08b3b474e351
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 5a3bbb55851b84aa6a46c23e5a6fb33b4860edc6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index ac7564f36a..71cfbd054b 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -2837,7 +2837,8 @@ void tst_QFuture::continuationsWithContext() // .then() { - auto future = QtFuture::makeReadyFuture(0) + QPromise<int> promise; + auto future = promise.future() .then([&](int val) { if (QThread::currentThread() != tstThread) return 0; @@ -2854,12 +2855,16 @@ void tst_QFuture::continuationsWithContext() return 0; return val + 1; }); + promise.start(); + promise.addResult(0); + promise.finish(); QCOMPARE(future.result(), 3); } // .onCanceled { - auto future = createCanceledFuture<int>() + QPromise<int> promise; + auto future = promise.future() .onCanceled(context, [&] { if (QThread::currentThread() != &thread) @@ -2871,13 +2876,17 @@ void tst_QFuture::continuationsWithContext() return 0; return val + 1; }); + promise.start(); + promise.future().cancel(); + promise.finish(); QCOMPARE(future.result(), 2); } #ifndef QT_NO_EXCEPTIONS // .onFaled() { - auto future = QtFuture::makeReadyFuture() + QPromise<void> promise; + auto future = promise.future() .then([&] { if (QThread::currentThread() != tstThread) return 0; @@ -2894,6 +2903,8 @@ void tst_QFuture::continuationsWithContext() return 0; return val + 1; }); + promise.start(); + promise.finish(); QCOMPARE(future.result(), 2); } #endif // QT_NO_EXCEPTIONS |