Skip to content
Permalink
Browse files
Improve stability of QgsTask::waitForFinished test
  • Loading branch information
m-kuhn committed May 12, 2017
1 parent 4180846 commit f9842426dccac3b44472f22362191c98bdc34deb
@@ -175,6 +175,8 @@ class QgsTask : QObject
Blocks the current thread until the task finishes or a maximum of ``timeout`` milliseconds.
If the ``timeout`` is ``-1`` the thread will be blocked forever.
In case of a timeout, the task will still be running.
In case the task already is finished, the method will return immediately while
returning ``true``.

The result will be false if the wait timed out and true in any other case.
:rtype: bool
@@ -158,6 +158,8 @@ bool QgsTask::waitForFinished( int timeout )
connect( &timer, &QTimer::timeout, &loop, &QEventLoop::quit );
}

if ( status() == QgsTask::Complete || status() == QgsTask::Terminated )
return true;
loop.exec();

return rv;
@@ -190,6 +190,8 @@ class CORE_EXPORT QgsTask : public QObject
* Blocks the current thread until the task finishes or a maximum of \a timeout milliseconds.
* If the \a timeout is ``-1`` the thread will be blocked forever.
* In case of a timeout, the task will still be running.
* In case the task already is finished, the method will return immediately while
* returning ``true``.
*
* The result will be false if the wait timed out and true in any other case.
*/
@@ -671,7 +671,6 @@ void TestQgsTaskManager::waitForFinished()
QTimer timer;
connect( &timer, &QTimer::timeout, finishedTask, &ProgressReportingTask::finish );
timer.start( 100 );
QCOMPARE( finishedTask->status(), QgsTask::Running );
QCOMPARE( finishedTask->waitForFinished(), true );
QCOMPARE( finishedTask->status(), QgsTask::Complete );

@@ -683,7 +682,6 @@ void TestQgsTaskManager::waitForFinished()

connect( &timer, &QTimer::timeout, failedTask, &ProgressReportingTask::terminate );
timer.start( 100 );
QCOMPARE( failedTask->status(), QgsTask::Running );
QCOMPARE( failedTask->waitForFinished(), true );
QCOMPARE( failedTask->status(), QgsTask::Terminated );

@@ -695,7 +693,6 @@ void TestQgsTaskManager::waitForFinished()

connect( &timer, &QTimer::timeout, timeoutTooShortTask, &ProgressReportingTask::finish );
timer.start( 1000 );
QCOMPARE( timeoutTooShortTask->status(), QgsTask::Running );
QCOMPARE( timeoutTooShortTask->waitForFinished( 20 ), false );
QCOMPARE( timeoutTooShortTask->status(), QgsTask::Running );
}

0 comments on commit f984242

Please sign in to comment.