Skip to content

Instantly share code, notes, and snippets.

@antony
Created July 4, 2013 13:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antony/5927831 to your computer and use it in GitHub Desktop.
Save antony/5927831 to your computer and use it in GitHub Desktop.
Parallelise your Grails functional tests! Put this in your scripts dir.
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