summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-06-20 15:46:00 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-22 04:12:41 +0000
commit841f04f3094ab398f98d8f85173b63101fd65640 (patch)
tree4e52ac8dea794bf5ddec00a36ffb5133ab70ca54 /tests
parent453fbbc2e83f0caf75c9680e4a3f5c29d1489b32 (diff)
QPromise: run continuation(s) on destruction
If the QFuture is canceled because the associated QPromise has been destroyed, we still need to run its continuations (i.e. onCanceled handler, if it's attached), so replaced the cleanContinuation() call inside ~QPromise() with runContinuation(), which will also take care of cleaning the continuation. [ChangeLog][QtCore][Important Behavior Changes] QFuture now runs its continuations when its associated QPromise has been destroyed. Previously, if a QFuture was canceled because the associated QPromise has been destroyed, its continuations were skipped. Fixes: QTBUG-103992 Change-Id: Ie05bc760c96c349aade8adb8d2fe5263aff8efac Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit bf3fc5c95cb4e6acedf242c00b7a1c3b455062bb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/thread/qpromise/tst_qpromise.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
index 5de8ce13ab..12206aa9fc 100644
--- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
+++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp
@@ -40,6 +40,7 @@ private slots:
#endif
void cancelWhenReassigned();
void cancelWhenDestroyedWithoutStarting();
+ void cancelWhenDestroyedRunsContinuations();
void finishWhenSwapped();
void cancelWhenMoved();
void waitUntilResumed();
@@ -494,6 +495,25 @@ void tst_QPromise::cancelWhenDestroyedWithoutStarting()
QVERIFY(future.isFinished());
}
+void tst_QPromise::cancelWhenDestroyedRunsContinuations()
+{
+ QFuture<void> future;
+ bool onCanceledCalled = false;
+ bool thenCalled = false;
+ {
+ QPromise<void> promise;
+ future = promise.future();
+ future.then([&] {
+ thenCalled = true;
+ }).onCanceled([&] {
+ onCanceledCalled = true;
+ });
+ }
+ QVERIFY(future.isFinished());
+ QVERIFY(!thenCalled);
+ QVERIFY(onCanceledCalled);
+}
+
void tst_QPromise::finishWhenSwapped()
{
#if !QT_CONFIG(cxx11_future)