Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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