Skip to content

Commit fc092cb

Browse files
authored
Merge pull request apache-spark-on-k8s#330 from palantir/ds/merge-test-results-scala
Cache & merge scala test results, bump parallelism
2 parents 08c5e0f + fc44d4f commit fc092cb

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

.circleci/config.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ test-defaults: &test-defaults
1212
<<: *defaults
1313
environment:
1414
CIRCLE_TEST_REPORTS: /tmp/circle-test-reports
15+
TEST_RESULTS_FILE: /tmp/test-results/results.json
1516

1617

1718
all-branches-and-tags: &all-branches-and-tags
@@ -239,7 +240,7 @@ jobs:
239240
run-scala-tests:
240241
<<: *test-defaults
241242
# project/CirclePlugin.scala does its own test splitting in SBT based on CIRCLE_NODE_INDEX, CIRCLE_NODE_TOTAL
242-
parallelism: 6
243+
parallelism: 12
243244
# Spark runs a lot of tests in parallel, we need 16 GB of RAM for this
244245
resource_class: xlarge
245246
steps:
@@ -258,11 +259,42 @@ jobs:
258259
- restore_cache:
259260
keys:
260261
- v2-home-sbt-{{ checksum "build/sbt" }}-{{ checksum "project/target/streams/$global/update/$global/streams/update_cache_2.10/inputs" }}
262+
- restore_cache:
263+
keys:
264+
- v1-test-results-{{ .Branch }}-{{ .BuildNum }}
265+
- v1-test-results-{{ .Branch }}-
266+
- v1-test-results-master-
267+
- run:
268+
name: Merge cached test results with results provided by circle (if any)
269+
command: |
270+
[[ -f "$CIRCLE_INTERNAL_TASK_DATA/circle-test-results/results.json" ]] && circle_exists=1
271+
[[ -f "$TEST_RESULTS_FILE" ]] && cached_exists=1
272+
if [[ -z "$circle_exists" ]] || [[ -z "$cached_exists" ]]; then
273+
# Only one exists, CirclePlugin will try to look for both so we're good.
274+
exit 0
275+
fi
276+
277+
# Otherwise, combine the two, preferring newer results from circle test results
278+
echo "Found both cached and circle test results, merging"
279+
jq -s 'def meld:
280+
reduce .[] as $o
281+
({}; reduce ($o|keys)[] as $key (.; .[$key] += [$o[$key]] ));
282+
def grp: map([{key: "\(.source)~\(.classname)", value: .}] | from_entries) | meld;
283+
((.[0].tests | grp) * (.[1].tests | grp)) | map(values) | flatten | {tests: .}' \
284+
"$TEST_RESULTS_FILE" \
285+
"$CIRCLE_INTERNAL_TASK_DATA/circle-test-results/results.json" \
286+
> /tmp/new-test-results.json
287+
# Overwrite the previously cached results with the merged file
288+
mv -f /tmp/new-test-results.json "$TEST_RESULTS_FILE"
261289
- run:
262290
name: Run all tests
263291
command: ./dev/run-scala-tests.py \
264292
| tee -a "/tmp/run-scala-tests.log"
265293
no_output_timeout: 15m
294+
- save_cache:
295+
key: v1-test-results-{{ .Branch }}-{{ .BuildNum }}
296+
paths:
297+
- "/tmp/test-results"
266298
- store_artifacts:
267299
path: /tmp/run-scala-tests.log
268300
destination: run-scala-tests.log

project/CirclePlugin.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,20 @@ object CirclePlugin extends AutoPlugin {
7777
log.info(s"Discovered tests in these projects: ${byProject.map(_.project.project)}")
7878

7979
import collection.JavaConverters._
80-
// Get timings and sum them up by TestKey = (source, classname)
81-
val testResultsFile = sys.env.get("CIRCLE_INTERNAL_TASK_DATA")
80+
val fromCircle = sys.env.get("CIRCLE_INTERNAL_TASK_DATA")
8281
.map(taskData => file(taskData) / "circle-test-results/results.json")
83-
.filter(file => file.exists())
82+
val fromCached = sys.env.get("TEST_RESULTS_FILE").map(file)
83+
84+
val testResultsFile = List(fromCached, fromCircle)
85+
.collectFirst {
86+
case Some(file) if file.exists() =>
87+
log.info(s"Using circle test results to determine test packing: $file")
88+
file
89+
}
90+
// Get timings and sum them up by TestKey = (source, classname)
8491
val testTimings = try {
85-
testResultsFile.fold {
86-
log.warn("Couldn't find circle test results file, using naive test packing")
87-
} {
88-
file => log.info(s"Using circle test results to determine test packing: $file")
92+
if (testResultsFile.isEmpty) {
93+
log.warn("Couldn't find any circle test results file, using naive test packing")
8994
}
9095
testResultsFile
9196
.map(file => {

0 commit comments

Comments
 (0)