Skip to content

Instantly share code, notes, and snippets.

@wf-adamhei
Created February 6, 2021 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wf-adamhei/83bafd3d992b881fb78cff8259fe74d7 to your computer and use it in GitHub Desktop.
Save wf-adamhei/83bafd3d992b881fb78cff8259fe74d7 to your computer and use it in GitHub Desktop.
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