Created
July 4, 2013 13:41
-
-
Save antony/5927831 to your computer and use it in GitHub Desktop.
Parallelise your Grails functional tests! Put this in your scripts dir.
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
import org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport | |
import org.codehaus.groovy.grails.test.GrailsTestTypeResult | |
import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher | |
import org.codehaus.groovy.grails.test.GrailsTestTargetPattern | |
includeTargets << grailsScript("_GrailsClean") | |
includeTargets << grailsScript("_GrailsTest") | |
// grails t-s shard=1 shards=4 | |
target('default': "Run functional test shard") { | |
depends(checkVersion, configureProxy, parseArguments, cleanTestReports) | |
List<String> tests = new SpecFinder(binding).testClassNames.sort() | |
int shards = (args =~ /shards=([0-9]*)/)[0][1] as Integer | |
int shard = ((args =~ /shard=([0-9]*)/)[0][1] as Integer) - 1 | |
int shardSize = tests.size() / shards+1 | |
List<List<String>> shardedTests = tests.collate(shardSize, true) | |
testNames = shardedTests[shard] | |
phasesToRun = ['functional'] | |
testOptions.https = true | |
testOptions.war = false | |
allTests() | |
} | |
class SpecFinder extends GrailsTestTypeSupport { | |
SpecFinder(binding) { | |
super('name', 'functional') | |
buildBinding = binding | |
} | |
int doPrepare() { | |
0 | |
} | |
GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher) { | |
null | |
} | |
List<String> getTestClassNames() { | |
findSourceFiles(new GrailsTestTargetPattern('**.*Spec')).sort{ -it.length() }.collect{ sourceFileToClassName(it) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment