lucene/gradle/testing/defaults-tests.gradle

104 lines
3.2 KiB
Groovy
Raw Normal View History

2019-12-02 09:34:57 -05:00
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.testing.logging.*
def verboseModeHookInstalled = false
2019-12-02 09:34:57 -05:00
allprojects {
plugins.withType(JavaPlugin) {
def verboseMode = Boolean.parseBoolean(propertyOrDefault("tests.verbose", "false"))
2019-12-02 09:34:57 -05:00
project.ext {
testsWorkDir = file("${buildDir}/tmp/tests-cwd")
testsTmpDir = file("${buildDir}/tmp/tests-tmp")
commonDir = project(":lucene").projectDir
commonSolrDir = project(":solr").projectDir
2019-12-02 09:34:57 -05:00
}
// If we're running in verbose mode and:
// 1) worker count > 1
// 2) number of 'test' tasks in the build is > 1
// then the output would very likely be mangled on the
// console. Fail and let the user know what to do.
if (verboseMode && !verboseModeHookInstalled) {
verboseModeHookInstalled = true
if (gradle.startParameter.maxWorkerCount > 1) {
gradle.taskGraph.whenReady { graph ->
def testTasks = graph.allTasks.findAll { task -> task instanceof Test }
if (testTasks.size() > 1) {
throw new GradleException("Run your tests in verbose mode only with --max-workers=1 option passed to gradle.")
}
}
}
}
2019-12-02 09:34:57 -05:00
test {
if (verboseMode) {
maxParallelForks = 1
} else {
maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))
}
2019-12-02 09:34:57 -05:00
workingDir testsWorkDir
2019-12-02 09:34:57 -05:00
useJUnit()
minHeapSize = "256m"
maxHeapSize = "512m"
systemProperty 'java.util.logging.config.file', file("${commonDir}/tools/junit4/logging.properties")
2019-12-02 09:34:57 -05:00
systemProperty 'java.awt.headless', 'true'
systemProperty 'jdk.map.althashing.threshold', '0'
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
systemProperty 'java.security.egd', 'file:/dev/./urandom'
}
// jetty-related.
systemProperty 'jetty.testMode', '1'
systemProperty 'jetty.insecurerandom', '1'
// Turn jenkins blood red for hashmap bugs, even on jdk7
systemProperty 'jdk.map.althashing.threshold', '0'
// Pass these to RandomizedRunner so that it doesn't attempt to set them.
systemProperty 'junit4.childvm.count', '1'
systemProperty 'junit4.childvm.id', '0'
2019-12-02 09:34:57 -05:00
// Set up cwd and temp locations.
systemProperty("java.io.tmpdir", testsTmpDir)
systemProperty("tempDir", testsTmpDir)
2019-12-02 09:34:57 -05:00
doFirst {
testsWorkDir.mkdirs()
testsTmpDir.mkdirs()
}
// Set up logging.
if (verboseMode) {
testLogging {
events TestLogEvent.FAILED
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
showStandardStreams = false
}
onOutput { td, event ->
print event.message
}
} else {
testLogging {
events TestLogEvent.FAILED
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
}
2019-12-02 09:34:57 -05:00
}
doFirst {
// Print some diagnostics about locations used.
logger.info("Test folders for {}: cwd={}, tmp={}", project.path, testsWorkDir, testsTmpDir)
}
}
}
}