forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Replace usages RandomizedTestingTask with built-in Gradle Test (
elastic#40564)" This reverts commit 2b2a3f5
- Loading branch information
1 parent
96adb04
commit 9a1fd06
Showing
97 changed files
with
1,552 additions
and
666 deletions.
There are no files selected for viewing
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
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
53 changes: 53 additions & 0 deletions
53
buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/BalancersConfiguration.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.carrotsearch.gradle.junit4 | ||
|
||
import com.carrotsearch.ant.tasks.junit4.SuiteBalancer | ||
import com.carrotsearch.ant.tasks.junit4.balancers.ExecutionTimeBalancer | ||
import com.carrotsearch.ant.tasks.junit4.listeners.ExecutionTimesReport | ||
import org.apache.tools.ant.types.FileSet | ||
|
||
class BalancersConfiguration { | ||
// parent task, so executionTime can register an additional listener | ||
RandomizedTestingTask task | ||
List<SuiteBalancer> balancers = new ArrayList<>() | ||
|
||
void executionTime(Map<String,Object> properties) { | ||
ExecutionTimeBalancer balancer = new ExecutionTimeBalancer() | ||
|
||
FileSet fileSet = new FileSet() | ||
Object filename = properties.remove('cacheFilename') | ||
if (filename == null) { | ||
throw new IllegalArgumentException('cacheFilename is required for executionTime balancer') | ||
} | ||
fileSet.setIncludes(filename.toString()) | ||
|
||
File cacheDir = task.project.projectDir | ||
Object dir = properties.remove('cacheDir') | ||
if (dir != null) { | ||
cacheDir = new File(dir.toString()) | ||
} | ||
fileSet.setDir(cacheDir) | ||
balancer.add(fileSet) | ||
|
||
int historySize = 10 | ||
Object size = properties.remove('historySize') | ||
if (size instanceof Integer) { | ||
historySize = (Integer)size | ||
} else if (size != null) { | ||
throw new IllegalArgumentException('historySize must be an integer') | ||
} | ||
ExecutionTimesReport listener = new ExecutionTimesReport() | ||
listener.setFile(new File(cacheDir, filename.toString())) | ||
listener.setHistoryLength(historySize) | ||
|
||
if (properties.isEmpty() == false) { | ||
throw new IllegalArgumentException('Unknown properties for executionTime balancer: ' + properties.keySet()) | ||
} | ||
|
||
task.listenersConfig.listeners.add(listener) | ||
balancers.add(balancer) | ||
} | ||
|
||
void custom(SuiteBalancer balancer) { | ||
balancers.add(balancer) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/ListenersConfiguration.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.carrotsearch.gradle.junit4 | ||
|
||
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener | ||
import com.carrotsearch.ant.tasks.junit4.listeners.antxml.AntXmlReport | ||
|
||
|
||
class ListenersConfiguration { | ||
RandomizedTestingTask task | ||
List<AggregatedEventListener> listeners = new ArrayList<>() | ||
|
||
void junitReport(Map<String, Object> props) { | ||
AntXmlReport reportListener = new AntXmlReport() | ||
Object dir = props == null ? null : props.get('dir') | ||
if (dir != null) { | ||
reportListener.setDir(task.project.file(dir)) | ||
} else { | ||
reportListener.setDir(new File(task.project.buildDir, 'reports' + File.separator + "${task.name}Junit")) | ||
} | ||
listeners.add(reportListener) | ||
} | ||
|
||
void custom(AggregatedEventListener listener) { | ||
listeners.add(listener) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...csearch/gradle/LoggingOutputStream.groovy → .../gradle/junit4/LoggingOutputStream.groovy
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
60 changes: 60 additions & 0 deletions
60
buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.carrotsearch.gradle.junit4 | ||
|
||
import com.carrotsearch.ant.tasks.junit4.JUnit4 | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.TaskContainer | ||
|
||
class RandomizedTestingPlugin implements Plugin<Project> { | ||
|
||
void apply(Project project) { | ||
String seed = setupSeed(project) | ||
createUnitTestTask(project.tasks) | ||
configureAnt(project.ant, seed) | ||
} | ||
|
||
/** | ||
* Pins the test seed at configuration time so it isn't different on every | ||
* {@link RandomizedTestingTask} execution. This is useful if random | ||
* decisions in one run of {@linkplain RandomizedTestingTask} influence the | ||
* outcome of subsequent runs. Pinning the seed up front like this makes | ||
* the reproduction line from one run be useful on another run. | ||
*/ | ||
static String setupSeed(Project project) { | ||
if (project.rootProject.ext.has('testSeed')) { | ||
/* Skip this if we've already pinned the testSeed. It is important | ||
* that this checks the rootProject so that we know we've only ever | ||
* initialized one time. */ | ||
return project.rootProject.ext.testSeed | ||
} | ||
String testSeed = System.getProperty('tests.seed') | ||
if (testSeed == null) { | ||
long seed = new Random(System.currentTimeMillis()).nextLong() | ||
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT) | ||
} | ||
/* Set the testSeed on the root project first so other projects can use | ||
* it during initialization. */ | ||
project.rootProject.ext.testSeed = testSeed | ||
project.rootProject.subprojects { | ||
project.ext.testSeed = testSeed | ||
} | ||
|
||
return testSeed | ||
} | ||
|
||
static void createUnitTestTask(TaskContainer tasks) { | ||
// only create a unitTest task if the `test` task exists as some project don't make use of it. | ||
tasks.matching { it.name == "test" }.all { | ||
// We don't want to run any tests with the Gradle test runner since we add our own randomized runner | ||
it.enabled = false | ||
RandomizedTestingTask unitTest = tasks.create('unitTest', RandomizedTestingTask) | ||
unitTest.description = 'Runs unit tests with the randomized testing framework' | ||
it.dependsOn unitTest | ||
} | ||
} | ||
|
||
static void configureAnt(AntBuilder ant, String seed) { | ||
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class) | ||
ant.properties.put('tests.seed', seed) | ||
} | ||
} |
Oops, something went wrong.