Skip to content

Commit 7fb752e

Browse files
authoredMar 27, 2019
[TRAVIS] run flaky test when label is defined (#9509)
to declare a test as flaky: * for cpp, use ``` if ( !QgsTest::runFlakyTests() ) QSKIP( "This test is disabled on Travis CI environment" ); ``` * for Python, you can use `RUN_FLAKY_TEST` environment variable
1 parent b9fdd02 commit 7fb752e

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed
 

‎.ci/travis/linux/docker-variables.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# Env variables for Docker
3-
# These without assignment are taken from the host env variabbles
3+
# These without assignment are taken from the host env variables
44

55
# TRAVIS variables
66
TRAVIS_AVAILABLE_TIME
@@ -11,6 +11,7 @@ TRAVIS_PULL_REQUEST
1111
TRAVIS_OS_NAME
1212
TRAVIS_CONFIG
1313
TRAVIS
14+
RUN_FLAKY_TESTS
1415

1516
# CTEST
1617
LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so

‎.ci/travis/linux/script.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
set -e
1818

19+
echo "Running flaky test: ${RUN_FLAKY_TESTS}"
20+
1921
# build QGIS in docker
2022
echo "travis_fold:start:docker_build_qgis"
2123
echo "${bold}Docker build QGIS${endbold}"

‎.ci/travis/scripts/pr_has_label.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import json
5+
from urllib.request import urlopen # using urllib since it is a standard module (vs. requests)
6+
from urllib.error import URLError
7+
import argparse
8+
9+
parser = argparse.ArgumentParser(description='Determines if a pull request has a defined label')
10+
parser.add_argument('pull_request', type=int,
11+
help='pull request id')
12+
parser.add_argument('label', type=int,
13+
help='label ID')
14+
15+
args = parser.parse_args()
16+
17+
url = "https://api.github.com/repos/qgis/QGIS/pulls/{}".format(args.pull_request)
18+
19+
try:
20+
data = urlopen(url).read().decode('utf-8')
21+
except URLError as err:
22+
print("URLError: ".format(err.reason))
23+
sys.exit(1)
24+
25+
obj = json.loads(data)
26+
27+
for label in obj['labels']:
28+
if label["id"] == args.label:
29+
print("true")
30+
sys.exit(0)
31+
32+
print("label not found")
33+
sys.exit(1)

‎.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cache:
1111
- ${HOME}/.ccache_docker_build_cosmic
1212
- ${HOME}/.ccache_docker_build_bionic
1313
timeout: 1000
14-
if: NOT branch =~ /^(cherry-pick-)?backport-\d+-on-/ AND NOT branch =~ /-patch-\d+$/
14+
if: NOT branch =~ /^(cherry-pick-)?backport-\d+-on-/ AND NOT branch =~ /-patch-\d+$/
1515

1616
env:
1717
global:
@@ -46,6 +46,8 @@ matrix:
4646
- CCACHE_DIR=${HOME}/.ccache_testing
4747
- DOCKER_TAG=$( [[ $TRAVIS_REPO_SLUG =~ qgis/QGIS ]] && echo $TRAVIS_BRANCH | sed 's/master/latest/' || echo "latest" )
4848
- DOCKER_BUILD_DEPS_FILE=qgis3-build-deps.dockerfile
49+
# Label ID can be found here https://api.github.com/repos/qgis/QGIS/labels
50+
- RUN_FLAKY_TESTS=$(.ci/travis/scripts/pr_has_label.py $TRAVIS_PULL_REQUEST 1271248184)
4951

5052
##########################################################
5153
# CODE LAYOUT

‎src/test/qgstest.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ namespace QgsTest
8383
{
8484
return qgetenv( "TRAVIS" ) == QStringLiteral( "true" );
8585
}
86+
87+
bool runFlakyTests()
88+
{
89+
return qgetenv( "RUN_FLAKY_TESTS" ) == QStringLiteral( "true" );
90+
}
8691
}
8792

8893
#endif // QGSTEST_H

‎tests/src/providers/testqgsogrprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void TestQgsOgrProvider::testThread()
187187
// Disabled by @m-kuhn
188188
// This test is flaky
189189
// See https://travis-ci.org/qgis/QGIS/jobs/505008602#L6464-L7108
190-
if ( QgsTest::isTravis() )
190+
if ( !QgsTest::runFlakyTests() )
191191
QSKIP( "This test is disabled on Travis CI environment" );
192192

193193
// After reading a QgsVectorLayer (getFeatures) from another thread the QgsOgrConnPoolGroup starts

0 commit comments

Comments
 (0)
Please sign in to comment.