Created
February 6, 2021 02:38
-
-
Save wf-adamhei/83bafd3d992b881fb78cff8259fe74d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
partitioned_test_cases = [] | |
pipeline { | |
agent { label ‘iOS’ } | |
environment { | |
TARGET_PARALLEL_AGENTS = 3 | |
} | |
stages { | |
stage(‘Partition UI Tests’) { | |
steps { | |
script { | |
// Parallel Executor Plugin (PEP) returns one extra empty split if generateInclusions == true | |
def parallelism = count((env.TARGET_PARALLEL_AGENTS as Integer) + 1) | |
def splits = splitTests parallelism: parallelism, | |
estimateTestsFromFiles: true, | |
generateInclusions: true | |
def includedSplitLists = splits.findAll { it.includes }.collect { it.list } | |
// PEP adds Java extensions to test cases | |
def formattedSplitLists = includedSplitLists.collect{ it.collect { it.minus(“.class”).minus(“.java”) }.unique() } | |
if (formattedSplitLists.size() == 0) { | |
// `splitTests` found nothing in the previous build | |
(env.TARGET_PARALLEL_AGENTS as Integer).times { | |
formattedSplitLists.push([]) | |
} | |
} | |
def allTestClassNames = getAllUITestClassNames() | |
def testClassNamesWithScheme = allTestClassNames.collect { “WealthfrontUITests/${it}” } | |
def allTestClassNamesFromPreviousBuild = formattedSplitLists.flatten() | |
def testClassNamesNotPreviouslyTested = testClassNamesWithScheme - allTestClassNamesFromPreviousBuild | |
// Add residual tests not in previous build, or naively partition tests if plugin found no test results in previous build | |
def index = 0 | |
for (int i = 0; i < testClassNamesNotPreviouslyTested.size(); i++) { | |
formattedSplitLists[index % formattedSplitLists.size()] += testClassNamesNotPreviouslyTested[i] | |
index++ | |
} | |
partitioned_test_cases = formattedSplitLists | |
} | |
} | |
} | |
stage(‘Parallel Execution’) { | |
steps { | |
runTestsInParallel() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment