forked from pantsbuild/pants
-
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.
New -default-concurrency parameter to junit-runner
Followon to https://rbcommons.com/s/twitter/r/3707/ this creates a new command line parameter for the JUnit runner that will allow us to more precisely specify the type of concurrency desired. Testing Done: Updated ConsoleRunnerTest and added two new test cases to show serial behavior for classes not annotated with @TestSerial CI green at https://travis-ci.org/pantsbuild/pants/builds/125445433 Bugs closed: 3191, 3265 Reviewed at https://rbcommons.com/s/twitter/r/3753/
- Loading branch information
1 parent
d5c18bd
commit 94388b3
Showing
7 changed files
with
195 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.pantsbuild.tools.junit.impl; | ||
|
||
public enum Concurrency { | ||
SERIAL(false, false), | ||
PARALLEL_CLASSES(true, false), | ||
PARALLEL_METHODS(false, true), | ||
PARALLEL_BOTH(true, true); | ||
|
||
private final boolean parallelClasses; | ||
private final boolean parallelMethods; | ||
|
||
Concurrency(boolean parallelClasses, boolean parallelMethods) { | ||
this.parallelClasses = parallelClasses; | ||
this.parallelMethods = parallelMethods; | ||
} | ||
|
||
public boolean shouldRunClassesParallel() { | ||
return parallelClasses; | ||
} | ||
|
||
public boolean shouldRunMethodsParallel() { | ||
return parallelMethods; | ||
} | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
tests/java/org/pantsbuild/tools/junit/lib/SerialTest1.java
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,43 @@ | ||
// Copyright 2016 Pants project contributors (see CONTRIBUTORS.md). | ||
// Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
package org.pantsbuild.tools.junit.lib; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.junit.Test; | ||
import org.pantsbuild.junit.annotations.TestSerial; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* This test is intentionally under a java_library() BUILD target so it will not be run | ||
* on its own. It is run by the ConsoleRunnerTest suite to test ConsoleRunnerImpl. | ||
* <p> | ||
* This test is just like {@link AnnotatedSerialTest1} but without the annotation. | ||
* Exercises the -default-concurrency SERIAL option | ||
* <p> | ||
* These tests are intended to show that the two classes will be run serially, even if | ||
* parallel test running is on. | ||
* To properly exercise this function, both test classes must be running at the same time with | ||
* the option -default-concurrency SERIAL option when running with just these two classes as specs. | ||
* <p> | ||
* Uses a timeout, so its not completely deterministic, but it gives 3 seconds to allow any | ||
* concurrency to take place. | ||
* </p> | ||
*/ | ||
public class SerialTest1 { | ||
private static final int WAIT_TIMEOUT_MS = 3000; | ||
private static AtomicBoolean waiting = new AtomicBoolean(false); | ||
|
||
@Test | ||
public void stest1() throws Exception { | ||
awaitLatch("stest1"); | ||
} | ||
|
||
static void awaitLatch(String methodName) throws Exception { | ||
TestRegistry.registerTestCall(methodName); | ||
assertFalse(waiting.getAndSet(true)); | ||
Thread.sleep(WAIT_TIMEOUT_MS); | ||
assertTrue(waiting.getAndSet(false)); | ||
} | ||
} |
Oops, something went wrong.