Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent tests wait for threads to be ready #42083

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public void testConcurrent() throws InterruptedException {
final AtomicInteger count = new AtomicInteger(0);
final CountDown countDown = new CountDown(scaledRandomIntBetween(10, 1000));
Thread[] threads = new Thread[between(3, 10)];
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch = new CountDownLatch(1 + threads.length);
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {

@Override
public void run() {
latch.countDown();
try {
latch.await();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void testIfMapEmptyAfterLotsOfAcquireAndReleases() throws InterruptedExce
for (int i = 0; i < names.length; i++) {
names[i] = randomRealisticUnicodeOfLengthBetween(10, 20);
}
CountDownLatch startLatch = new CountDownLatch(1);
int numThreads = randomIntBetween(3, 10);
final CountDownLatch startLatch = new CountDownLatch(1 + numThreads);
AcquireAndReleaseThread[] threads = new AcquireAndReleaseThread[numThreads];
for (int i = 0; i < numThreads; i++) {
threads[i] = new AcquireAndReleaseThread(startLatch, connectionLock, names, counter, safeCounter);
Expand Down Expand Up @@ -157,6 +157,7 @@ public AcquireAndReleaseThread(CountDownLatch startLatch, KeyedLock<String> conn

@Override
public void run() {
startLatch.countDown();
try {
startLatch.await();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public void testRunOnceConcurrently() throws InterruptedException {
final RunOnce runOnce = new RunOnce(counter::incrementAndGet);

final Thread[] threads = new Thread[between(3, 10)];
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch = new CountDownLatch(1 + threads.length);
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
latch.countDown();
try {
latch.await();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ public void testNodeStats() throws Exception {
public void testConcurrentAddingAndRemoving() throws Exception {
String[] nodes = new String[] {"a", "b", "c", "d"};

final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch = new CountDownLatch(5);

Runnable f = () -> {
latch.countDown();
try {
latch.await();
} catch (InterruptedException e) {
Expand Down