Skip to content

Commit 8abef21

Browse files
author
Marcelo Vanzin
committed
[SPARK-10300] [BUILD] [TESTS] Add support for test tags in run-tests.py.
This change does two things: - tag a few tests and adds the mechanism in the build to be able to disable those tags, both in maven and sbt, for both junit and scalatest suites. - add some logic to run-tests.py to disable some tags depending on what files have changed; that's used to disable expensive tests when a module hasn't explicitly been changed, to speed up testing for changes that don't directly affect those modules. Author: Marcelo Vanzin <[email protected]> Closes #8437 from vanzin/test-tags.
1 parent c35fdcb commit 8abef21

File tree

26 files changed

+124
-147
lines changed

26 files changed

+124
-147
lines changed

core/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,6 @@
331331
<artifactId>scalacheck_${scala.binary.version}</artifactId>
332332
<scope>test</scope>
333333
</dependency>
334-
<dependency>
335-
<groupId>junit</groupId>
336-
<artifactId>junit</artifactId>
337-
<scope>test</scope>
338-
</dependency>
339-
<dependency>
340-
<groupId>com.novocode</groupId>
341-
<artifactId>junit-interface</artifactId>
342-
<scope>test</scope>
343-
</dependency>
344334
<dependency>
345335
<groupId>org.apache.curator</groupId>
346336
<artifactId>curator-test</artifactId>

dev/run-tests.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ def determine_modules_to_test(changed_modules):
118118
return modules_to_test.union(set(changed_modules))
119119

120120

121+
def determine_tags_to_exclude(changed_modules):
122+
tags = []
123+
for m in modules.all_modules:
124+
if m not in changed_modules:
125+
tags += m.test_tags
126+
return tags
127+
128+
121129
# -------------------------------------------------------------------------------------------------
122130
# Functions for working with subprocesses and shell tools
123131
# -------------------------------------------------------------------------------------------------
@@ -369,6 +377,7 @@ def detect_binary_inop_with_mima():
369377

370378
def run_scala_tests_maven(test_profiles):
371379
mvn_test_goals = ["test", "--fail-at-end"]
380+
372381
profiles_and_goals = test_profiles + mvn_test_goals
373382

374383
print("[info] Running Spark tests using Maven with these arguments: ",
@@ -392,7 +401,7 @@ def run_scala_tests_sbt(test_modules, test_profiles):
392401
exec_sbt(profiles_and_goals)
393402

394403

395-
def run_scala_tests(build_tool, hadoop_version, test_modules):
404+
def run_scala_tests(build_tool, hadoop_version, test_modules, excluded_tags):
396405
"""Function to properly execute all tests passed in as a set from the
397406
`determine_test_suites` function"""
398407
set_title_and_block("Running Spark unit tests", "BLOCK_SPARK_UNIT_TESTS")
@@ -401,6 +410,10 @@ def run_scala_tests(build_tool, hadoop_version, test_modules):
401410

402411
test_profiles = get_hadoop_profiles(hadoop_version) + \
403412
list(set(itertools.chain.from_iterable(m.build_profile_flags for m in test_modules)))
413+
414+
if excluded_tags:
415+
test_profiles += ['-Dtest.exclude.tags=' + ",".join(excluded_tags)]
416+
404417
if build_tool == "maven":
405418
run_scala_tests_maven(test_profiles)
406419
else:
@@ -500,8 +513,10 @@ def main():
500513
target_branch = os.environ["ghprbTargetBranch"]
501514
changed_files = identify_changed_files_from_git_commits("HEAD", target_branch=target_branch)
502515
changed_modules = determine_modules_for_files(changed_files)
516+
excluded_tags = determine_tags_to_exclude(changed_modules)
503517
if not changed_modules:
504518
changed_modules = [modules.root]
519+
excluded_tags = []
505520
print("[info] Found the following changed modules:",
506521
", ".join(x.name for x in changed_modules))
507522

@@ -541,7 +556,7 @@ def main():
541556
detect_binary_inop_with_mima()
542557

543558
# run the test suites
544-
run_scala_tests(build_tool, hadoop_version, test_modules)
559+
run_scala_tests(build_tool, hadoop_version, test_modules, excluded_tags)
545560

546561
modules_with_python_tests = [m for m in test_modules if m.python_test_goals]
547562
if modules_with_python_tests:

dev/sparktestsupport/modules.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Module(object):
3131

3232
def __init__(self, name, dependencies, source_file_regexes, build_profile_flags=(), environ={},
3333
sbt_test_goals=(), python_test_goals=(), blacklisted_python_implementations=(),
34-
should_run_r_tests=False):
34+
test_tags=(), should_run_r_tests=False):
3535
"""
3636
Define a new module.
3737
@@ -50,6 +50,8 @@ def __init__(self, name, dependencies, source_file_regexes, build_profile_flags=
5050
:param blacklisted_python_implementations: A set of Python implementations that are not
5151
supported by this module's Python components. The values in this set should match
5252
strings returned by Python's `platform.python_implementation()`.
53+
:param test_tags A set of tags that will be excluded when running unit tests if the module
54+
is not explicitly changed.
5355
:param should_run_r_tests: If true, changes in this module will trigger all R tests.
5456
"""
5557
self.name = name
@@ -60,6 +62,7 @@ def __init__(self, name, dependencies, source_file_regexes, build_profile_flags=
6062
self.environ = environ
6163
self.python_test_goals = python_test_goals
6264
self.blacklisted_python_implementations = blacklisted_python_implementations
65+
self.test_tags = test_tags
6366
self.should_run_r_tests = should_run_r_tests
6467

6568
self.dependent_modules = set()
@@ -85,6 +88,9 @@ def contains_file(self, filename):
8588
"catalyst/test",
8689
"sql/test",
8790
"hive/test",
91+
],
92+
test_tags=[
93+
"org.apache.spark.sql.hive.ExtendedHiveTest"
8894
]
8995
)
9096

@@ -398,6 +404,22 @@ def contains_file(self, filename):
398404
)
399405

400406

407+
yarn = Module(
408+
name="yarn",
409+
dependencies=[],
410+
source_file_regexes=[
411+
"yarn/",
412+
"network/yarn/",
413+
],
414+
sbt_test_goals=[
415+
"yarn/test",
416+
"network-yarn/test",
417+
],
418+
test_tags=[
419+
"org.apache.spark.deploy.yarn.ExtendedYarnTest"
420+
]
421+
)
422+
401423
# The root module is a dummy module which is used to run all of the tests.
402424
# No other modules should directly depend on this module.
403425
root = Module(

external/flume/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@
6666
<artifactId>scalacheck_${scala.binary.version}</artifactId>
6767
<scope>test</scope>
6868
</dependency>
69-
<dependency>
70-
<groupId>junit</groupId>
71-
<artifactId>junit</artifactId>
72-
<scope>test</scope>
73-
</dependency>
74-
<dependency>
75-
<groupId>com.novocode</groupId>
76-
<artifactId>junit-interface</artifactId>
77-
<scope>test</scope>
78-
</dependency>
7969
</dependencies>
8070
<build>
8171
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>

external/kafka/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@
8686
<artifactId>scalacheck_${scala.binary.version}</artifactId>
8787
<scope>test</scope>
8888
</dependency>
89-
<dependency>
90-
<groupId>junit</groupId>
91-
<artifactId>junit</artifactId>
92-
<scope>test</scope>
93-
</dependency>
94-
<dependency>
95-
<groupId>com.novocode</groupId>
96-
<artifactId>junit-interface</artifactId>
97-
<scope>test</scope>
98-
</dependency>
9989
</dependencies>
10090
<build>
10191
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>

external/mqtt/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@
5858
<artifactId>scalacheck_${scala.binary.version}</artifactId>
5959
<scope>test</scope>
6060
</dependency>
61-
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
64-
<scope>test</scope>
65-
</dependency>
66-
<dependency>
67-
<groupId>com.novocode</groupId>
68-
<artifactId>junit-interface</artifactId>
69-
<scope>test</scope>
70-
</dependency>
7161
<dependency>
7262
<groupId>org.apache.activemq</groupId>
7363
<artifactId>activemq-core</artifactId>

external/twitter/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@
5858
<artifactId>scalacheck_${scala.binary.version}</artifactId>
5959
<scope>test</scope>
6060
</dependency>
61-
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
64-
<scope>test</scope>
65-
</dependency>
66-
<dependency>
67-
<groupId>com.novocode</groupId>
68-
<artifactId>junit-interface</artifactId>
69-
<scope>test</scope>
70-
</dependency>
7161
</dependencies>
7262
<build>
7363
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>

external/zeromq/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@
5757
<artifactId>scalacheck_${scala.binary.version}</artifactId>
5858
<scope>test</scope>
5959
</dependency>
60-
<dependency>
61-
<groupId>junit</groupId>
62-
<artifactId>junit</artifactId>
63-
<scope>test</scope>
64-
</dependency>
65-
<dependency>
66-
<groupId>com.novocode</groupId>
67-
<artifactId>junit-interface</artifactId>
68-
<scope>test</scope>
69-
</dependency>
7060
</dependencies>
7161
<build>
7262
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>

extras/java8-tests/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@
5858
<type>test-jar</type>
5959
<scope>test</scope>
6060
</dependency>
61-
<dependency>
62-
<groupId>junit</groupId>
63-
<artifactId>junit</artifactId>
64-
<scope>test</scope>
65-
</dependency>
66-
<dependency>
67-
<groupId>com.novocode</groupId>
68-
<artifactId>junit-interface</artifactId>
69-
<scope>test</scope>
70-
</dependency>
7161
</dependencies>
7262

7363
<profiles>

extras/kinesis-asl/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@
7474
<artifactId>scalacheck_${scala.binary.version}</artifactId>
7575
<scope>test</scope>
7676
</dependency>
77-
<dependency>
78-
<groupId>com.novocode</groupId>
79-
<artifactId>junit-interface</artifactId>
80-
<scope>test</scope>
81-
</dependency>
8277
</dependencies>
8378
<build>
8479
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>

0 commit comments

Comments
 (0)