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.
Add AnnotatedParallelClassesAndMethodsTest* and AnnotatedParallelMeth…
…odsTest* No bugs found, this just rounds out the testing of ConsoleRunnerImpl to make sure that the @TestParallelMethods and @TestParallelClassesAndMethods annotations take precedence over the -default-concurrency setting. Testing Done: CI green at https://travis-ci.org/pantsbuild/pants/builds/140545792 Bugs closed: 3605 Reviewed at https://rbcommons.com/s/twitter/r/4027/
- Loading branch information
1 parent
c432f6d
commit 0d796a7
Showing
8 changed files
with
205 additions
and
12 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
tests/java/org/pantsbuild/tools/junit/lib/AnnotatedParallelClassesAndMethodsTest1.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,53 @@ | ||
// 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.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.Test; | ||
import org.pantsbuild.junit.annotations.TestParallelClassesAndMethods; | ||
|
||
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> | ||
* Exercises the TestParallelClassesAndMethods annotation. | ||
* <p> | ||
* For all methods in AnnotatedParallelMethodsTest1 and AnnotatedParallelMethodsTest2 | ||
* to succeed, both test classes must be running at the same time with the flag: | ||
* <pre> | ||
* -parallel-threads 2 | ||
* </pre> | ||
* when running with just these two classes as specs. | ||
* <p> | ||
* Runs in on the order of 10 milliseconds locally, but it may take longer on a CI machine to spin | ||
* up 2 threads, so it has a generous timeout set. | ||
* </p> | ||
*/ | ||
@TestParallelClassesAndMethods | ||
public class AnnotatedParallelClassesAndMethodsTest1 { | ||
private static final int NUM_CONCURRENT_TESTS = 4; | ||
private static final int WAIT_TIMEOUT_MS = 3000; | ||
private static CountDownLatch latch = new CountDownLatch(NUM_CONCURRENT_TESTS); | ||
|
||
public static void reset() { | ||
latch = new CountDownLatch(NUM_CONCURRENT_TESTS); | ||
} | ||
|
||
@Test | ||
public void apmcatest11() throws Exception { | ||
awaitLatch("apcamtest11"); | ||
} | ||
|
||
@Test | ||
public void apmcatest12() throws Exception { | ||
awaitLatch("apcamtest12"); | ||
} | ||
static void awaitLatch(String methodName) throws Exception { | ||
TestRegistry.registerTestCall(methodName); | ||
latch.countDown(); | ||
assertTrue(latch.await(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/java/org/pantsbuild/tools/junit/lib/AnnotatedParallelClassesAndMethodsTest2.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,22 @@ | ||
// 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 org.junit.Test; | ||
import org.pantsbuild.junit.annotations.TestParallelClassesAndMethods; | ||
|
||
/** | ||
* See {@link AnnotatedParallelClassesAndMethodsTest1} | ||
*/ | ||
@TestParallelClassesAndMethods | ||
public class AnnotatedParallelClassesAndMethodsTest2 { | ||
|
||
@Test | ||
public void apcamtest21() throws Exception { | ||
AnnotatedParallelClassesAndMethodsTest1.awaitLatch("apcamtest21"); | ||
} | ||
@Test | ||
public void apcamtest22() throws Exception { | ||
AnnotatedParallelClassesAndMethodsTest1.awaitLatch("apcamtest22"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/java/org/pantsbuild/tools/junit/lib/AnnotatedParallelMethodsTest1.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,71 @@ | ||
// 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.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.junit.Test; | ||
import org.pantsbuild.junit.annotations.TestParallelMethods; | ||
|
||
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> | ||
* Exercises the TestParallelMethods annotation. | ||
* <p> | ||
* For all methods in AnnotatedParallelMethodsTest1 and AnnotatedParallelMethodsTest2 | ||
* to succeed, both test classes must be running at the same time with the flag: | ||
* <pre> | ||
* -parallel-threads 2 | ||
* </pre> | ||
* when running with just these two classes as specs. | ||
* <p> | ||
* Runs in on the order of 10 milliseconds locally, but it may take longer on a CI machine to spin | ||
* up 2 threads, so it has a generous timeout set. | ||
* </p> | ||
*/ | ||
@TestParallelMethods | ||
public class AnnotatedParallelMethodsTest1 { | ||
private static final int NUM_CONCURRENT_TESTS = 2; | ||
private static final int WAIT_TIMEOUT_MS = 3000; | ||
private static CountDownLatch latch = new CountDownLatch(NUM_CONCURRENT_TESTS); | ||
private static final AtomicInteger numRunning = new AtomicInteger(0); | ||
|
||
public static void reset() { | ||
latch = new CountDownLatch(NUM_CONCURRENT_TESTS); | ||
numRunning.set(0); | ||
} | ||
|
||
@Test | ||
public void apmtest11() throws Exception { | ||
awaitLatch("apmtest11"); | ||
} | ||
|
||
@Test | ||
public void apmtest12() throws Exception { | ||
awaitLatch("apmtest12"); | ||
} | ||
|
||
static void awaitLatch(String methodName) throws Exception { | ||
// NB(zundel): this test currently doesn't ensure that both classes run all methods in | ||
// parallel, but the classes run serially, it only ensures that at least two methods get | ||
// started and that no more than 2 methods run at a time. A better test would show that | ||
// methods are run in parallel in each class. | ||
|
||
TestRegistry.registerTestCall(methodName); | ||
latch.countDown(); | ||
// Make sure that we wait for at least 2 methods to get started to ensure there is some | ||
// parallelism going on. | ||
assertTrue(latch.await(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); | ||
numRunning.incrementAndGet(); | ||
Thread.sleep(WAIT_TIMEOUT_MS); | ||
// Make sure no more than 2 tests have been started concurrently | ||
int running = numRunning.get(); | ||
assertTrue(String.format("Expected <= %d got %d", NUM_CONCURRENT_TESTS, running), | ||
running <= NUM_CONCURRENT_TESTS); | ||
numRunning.decrementAndGet(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/java/org/pantsbuild/tools/junit/lib/AnnotatedParallelMethodsTest2.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,23 @@ | ||
// 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 org.junit.Test; | ||
import org.pantsbuild.junit.annotations.TestParallelMethods; | ||
|
||
/** | ||
* See {@link AnnotatedParallelMethodsTest1} | ||
*/ | ||
@TestParallelMethods | ||
public class AnnotatedParallelMethodsTest2 { | ||
|
||
@Test | ||
public void apmtest21() throws Exception { | ||
AnnotatedParallelMethodsTest1.awaitLatch("apmtest21"); | ||
} | ||
|
||
@Test | ||
public void apmtest22() throws Exception { | ||
AnnotatedParallelMethodsTest1.awaitLatch("apmtest22"); | ||
} | ||
} |
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