Skip to content

Commit

Permalink
Skip some task manager tests on Travis only
Browse files Browse the repository at this point in the history
Instead of #ifdefing them out, only prevent them running
on Travis so that they still run locally.

Also skip another task manager test which randomly
fails only on Travis
  • Loading branch information
nyalldawson committed Sep 4, 2017
1 parent 85e6a63 commit 2286710
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
13 changes: 13 additions & 0 deletions src/test/qgstest.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,18 @@
return QTest::qExec(&tc, argc, argv); \
}

/**
* QGIS unit test utilities.
* \since QGIS 3.0
*/
namespace QgsTest
{

//! Returns true if test is running on Travis infrastructure
bool isTravis()
{
return qgetenv( "TRAVIS" ) == QStringLiteral( "true" );
}
}

#endif // QGSTEST_H
42 changes: 18 additions & 24 deletions tests/src/core/testqgstaskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
#include <QObject>
#include "qgstest.h"

// some of these tests have intermittent failure on Travis, probably due
// to inconsistent availability to multiple threads on the platform.
// These tests are disabled unless WITH_FLAKY is 1.

#define WITH_FLAKY 0 //TODO - disable only for Travis?

class TestTask : public QgsTask
{
Q_OBJECT
Expand Down Expand Up @@ -200,15 +194,11 @@ class TestQgsTaskManager : public QObject
void task();
void taskResult();
void taskFinished();
#if WITH_FLAKY
void subTask();
#endif
void addTask();
void taskTerminationBeforeDelete();
void taskId();
#if WITH_FLAKY
void waitForFinished();
#endif
void progressChanged();
void statusChanged();
void allTasksFinished();
Expand Down Expand Up @@ -442,9 +432,11 @@ void TestQgsTaskManager::taskFinished()
QCOMPARE( *resultObtained, false );
}

#if WITH_FLAKY
void TestQgsTaskManager::subTask()
{
if ( QgsTest::isTravis() )
QSKIP( "This test is disabled on Travis CI environment" );

QgsTaskManager manager;

// parent with one subtask
Expand Down Expand Up @@ -489,29 +481,29 @@ void TestQgsTaskManager::subTask()
// test progress calculation
QSignalSpy spy( parent, &QgsTask::progressChanged );
parent->emitProgressChanged( 50 );
QCOMPARE( std::round( parent->progress() ), 17 );
QCOMPARE( std::round( parent->progress() ), 17.0 );
//QCOMPARE( spy.count(), 1 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 17 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 17.0 );

subTask->emitProgressChanged( 100 );
QCOMPARE( std::round( parent->progress() ), 50 );
QCOMPARE( std::round( parent->progress() ), 50.0 );
//QCOMPARE( spy.count(), 2 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 50 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 50.0 );

subTask2->finish();
while ( subTask2->status() != QgsTask::Complete )
{
QCoreApplication::processEvents();
}
flushEvents();
QCOMPARE( std::round( parent->progress() ), 83 );
QCOMPARE( std::round( parent->progress() ), 83.0 );
//QCOMPARE( spy.count(), 3 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 83 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 83.0 );

parent->emitProgressChanged( 100 );
QCOMPARE( std::round( parent->progress() ), 100 );
QCOMPARE( std::round( parent->progress() ), 100.0 );
//QCOMPARE( spy.count(), 4 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 100 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 100.0 );
parent->terminate();
subTask->terminate();

Expand Down Expand Up @@ -641,7 +633,6 @@ void TestQgsTaskManager::subTask()
flushEvents();
QVERIFY( parentFinished2.count() > 0 );
}
#endif

void TestQgsTaskManager::taskId()
{
Expand All @@ -665,9 +656,11 @@ void TestQgsTaskManager::taskId()
delete task3;
}

#if WITH_FLAKY
void TestQgsTaskManager::waitForFinished()
{
if ( QgsTest::isTravis() )
QSKIP( "This test is disabled on Travis CI environment" );

QgsTaskManager manager;
QEventLoop loop;

Expand Down Expand Up @@ -705,7 +698,6 @@ void TestQgsTaskManager::waitForFinished()
QCOMPARE( timeoutTooShortTask->waitForFinished( 20 ), false );
QCOMPARE( timeoutTooShortTask->status(), QgsTask::Running );
}
#endif

void TestQgsTaskManager::progressChanged()
{
Expand Down Expand Up @@ -1105,6 +1097,9 @@ void TestQgsTaskManager::layerDependencies()

void TestQgsTaskManager::managerWithSubTasks()
{
if ( QgsTest::isTravis() )
QSKIP( "This test is disabled on Travis CI environment" );

// parent with subtasks
ProgressReportingTask *parent = new ProgressReportingTask( "parent" );
ProgressReportingTask *subTask = new ProgressReportingTask( "subtask" );
Expand All @@ -1125,7 +1120,7 @@ void TestQgsTaskManager::managerWithSubTasks()
QCOMPARE( manager->activeTasks().count(), 1 );
QVERIFY( manager->activeTasks().contains( parent ) );
QCOMPARE( spy.count(), 1 );
#if WITH_FLAKY

//manager should not directly listen to progress reports from subtasks
//(only parent tasks, which themselves include their subtask progress)
QCOMPARE( spyProgress.count(), 0 );
Expand All @@ -1146,7 +1141,6 @@ void TestQgsTaskManager::managerWithSubTasks()
QCOMPARE( spyProgress.count(), 3 );
QCOMPARE( spyProgress.last().at( 0 ).toLongLong(), 0LL );
QCOMPARE( spyProgress.last().at( 1 ).toInt(), 63 );
#endif

//manager should not emit statusChanged signals for subtasks
QSignalSpy statusSpy( manager, &QgsTaskManager::statusChanged );
Expand Down

0 comments on commit 2286710

Please sign in to comment.