def concurrentMethod(String fileName, String threadName) { def args = ['-f', 'pretty', '--glue', 'src/test/groovy', 'src/test/resources'].join(" ") def classpath = configurations.cucumberRuntime.getAsPath() def main = "cucumber.api.cli.Main" logger.quiet "FileName: $fileName, ThreadName: $threadName" logger.quiet "Running command: \"java -cp $classpath $main $args\"" def process = "java -cp $classpath $main $args".execute() process.waitForOrKill(25000) logger.quiet "Process Out: ${process.text}" logger.quiet "Process Err: ${process.err}"}process.waitFor()
import groovyx.gpars.GParsPool
apply plugin: 'groovy'apply plugin: 'idea'
//build stuffsourceCompatibility = 1.6targetCompatibility = 1.6
configurations { cucumberRuntime { extendsFrom testRuntime }}
task cucumber() { dependsOn assemble doLast { javaexec { main = "cucumber.api.cli.Main" classpath = configurations.cucumberRuntime args = ['-f', 'pretty', '--glue', 'src/test/groovy', 'src/test/resources'] } }}
buildscript { repositories { mavenCentral() }
dependencies { classpath "org.codehaus.gpars:gpars:1.1.0" }}
dependencies { // Groovy library for groovy building! groovy 'org.codehaus.groovy:groovy-all:2.1.0' groovy 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' groovy 'org.slf4j:slf4j-api:1.7.+' groovy 'org.slf4j:slf4j-log4j12:1.7.5'
//In order to work around bug http://issues.gradle.org/browse/GRADLE-732 cucumberRuntime files("${jar.archivePath}")
testCompile 'junit:junit:4.11' testCompile 'info.cukes:cucumber-junit:1.1.5' testCompile 'info.cukes:cucumber-groovy:1.1.5'}
repositories { mavenCentral()}
def concurrentMethod(String fileName, String threadName) { def args = ['-f', 'pretty', '--glue', 'src/test/groovy', 'src/test/resources'].join(" ") def classpath = configurations.cucumberRuntime.getAsPath() def main = "cucumber.api.cli.Main" logger.quiet "FileName: $fileName, ThreadName: $threadName" logger.quiet "Running command: \"java -cp $classpath $main $args\"" def process = "java -cp $classpath $main $args".execute() process.waitForOrKill(25000) logger.quiet "Process Out: ${process.text}" logger.quiet "Process Err: ${process.err}"}
String getThreadName(names) { String currentName = Thread.currentThread().name if (!names.contains(currentName)) names << currentName
"t${names.indexOf(currentName).toString().padLeft(2, '0')}"}
task concurrentCucumber() { dependsOn assemble def cores = Runtime.runtime.availableProcessors() def threads = 10 println " > Using $threads threads on $cores cores..." def names = [] GParsPool.withPool(threads) { def features = fileTree(dir: 'src/test/resources').include '**/*.feature' features.eachParallel { File file -> def name = getThreadName(names) logger.quiet "File: ${file.name}" concurrentMethod(file.name, name) } } logger.quiet("Run complete!")}
task wrapper(type: Wrapper) { jarFile = 'wrapper/gradle-wrapper.jar' gradleVersion = "1.8"}In an attempt to make gradle run multiple feature files concurrently, I've tweaked the typical cucumber task, and it's actually (kind of) working. The project is here (on branch 'concurrent'): https://github.com/theaberrant/cucumber-jvm-groovy-rest-example/tree/concurrent
However, the java process doesn't exist properly - I see it in the running processes, but it has to be killed before the cucumber task completes.If I just use:def concurrentMethod(String fileName, String threadName) {def args = ['-f', 'pretty', '--glue', 'src/test/groovy', 'src/test/resources'].join(" ")def classpath = configurations.cucumberRuntime.getAsPath()def main = "cucumber.api.cli.Main"logger.quiet "FileName: $fileName, ThreadName: $threadName"logger.quiet "Running command: \"java -cp $classpath $main $args\""def process = "java -cp $classpath $main $args".execute()process.waitForOrKill(25000)logger.quiet "Process Out: ${process.text}"logger.quiet "Process Err: ${process.err}"}
Using the following doesn't work, since the java process never exits:process.waitFor()My hack solution is to add a kill timeout, however that's just to see it work.Any ideas why the java process doesn't exit? This does work when attempting to run a groovyscript file, as seen in my other project: https://github.com/theaberrant/gradle-concurrent. Any help would be greatly appreciated. Further technical details below.
Thanks,Tris