Skip to content

Commit

Permalink
Increase various tests' timeouts.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=268726044
  • Loading branch information
cpovirk authored and cgdecker committed Sep 13, 2019
1 parent aa73da8 commit e3c1457
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
public class AbstractServiceTest extends TestCase {

private static final long LONG_TIMEOUT_MILLIS = 2500;
private static final long LONG_TIMEOUT_MILLIS = 10000;
private Thread executionThread;
private Throwable thrownByExecutionThread;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;

/**
Expand All @@ -42,7 +37,7 @@ public class AtomicLongMapTest extends TestCase {
private static final int ITERATIONS = 100;
private static final int MAX_ADDEND = 100;

private Random random = new Random(301);
private final Random random = new Random(301);

@GwtIncompatible // NullPointerTester
public void testNulls() {
Expand Down Expand Up @@ -578,87 +573,4 @@ public void testSerialization() {
AtomicLongMap<String> reserialized = SerializableTester.reserialize(map);
assertEquals(map.asMap(), reserialized.asMap());
}

@GwtIncompatible // threads
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";

final AtomicLong sum = new AtomicLong();
final AtomicLongMap<String> map = AtomicLongMap.create();

ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
for (int i = 0; i < nTasks; i++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
int behavior = random.nextInt(10);
switch (behavior) {
case 0:
map.incrementAndGet(key);
threadSum++;
break;
case 1:
map.decrementAndGet(key);
threadSum--;
break;
case 2:
map.addAndGet(key, delta);
threadSum += delta;
break;
case 3:
map.getAndIncrement(key);
threadSum++;
break;
case 4:
map.getAndDecrement(key);
threadSum--;
break;
case 5:
map.getAndAdd(key, delta);
threadSum += delta;
break;
case 6:
long oldValue = map.put(key, delta);
threadSum += delta - oldValue;
break;
case 7:
oldValue = map.get(key);
if (map.replace(key, oldValue, delta)) {
threadSum += delta - oldValue;
}
break;
case 8:
oldValue = map.remove(key);
threadSum -= oldValue;
break;
case 9:
oldValue = map.get(key);
if (map.remove(key, oldValue)) {
threadSum -= oldValue;
}
break;
default:
throw new AssertionError();
}
}
sum.addAndGet(threadSum);
}
});
}

threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

assertEquals(sum.get(), map.get(key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public void testTransitionRace() throws TimeoutException {
}
ServiceManager manager = new ServiceManager(services);
manager.startAsync().awaitHealthy();
manager.stopAsync().awaitStopped(1, TimeUnit.SECONDS);
manager.stopAsync().awaitStopped(10, TimeUnit.SECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class SimpleTimeLimiterTest extends TestCase {

private static final long DELAY_MS = 50;
private static final long ENOUGH_MS = 500;
private static final long ENOUGH_MS = 10000;
private static final long NOT_ENOUGH_MS = 5;

private static final String GOOD_CALLABLE_RESULT = "good callable result";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testRegularFutureInterrupted() throws ExecutionException {

assertFalse(Thread.interrupted());
try {
delayedFuture.get(10000, TimeUnit.MILLISECONDS);
delayedFuture.get(20000, TimeUnit.MILLISECONDS);
fail("expected to be interrupted");
} catch (InterruptedException expected) {
} catch (TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
public class AbstractServiceTest extends TestCase {

private static final long LONG_TIMEOUT_MILLIS = 2500;
private static final long LONG_TIMEOUT_MILLIS = 10000;
private Thread executionThread;
private Throwable thrownByExecutionThread;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;

/**
Expand All @@ -42,7 +37,7 @@ public class AtomicLongMapTest extends TestCase {
private static final int ITERATIONS = 100;
private static final int MAX_ADDEND = 100;

private Random random = new Random(301);
private final Random random = new Random(301);

@GwtIncompatible // NullPointerTester
public void testNulls() {
Expand Down Expand Up @@ -578,87 +573,4 @@ public void testSerialization() {
AtomicLongMap<String> reserialized = SerializableTester.reserialize(map);
assertEquals(map.asMap(), reserialized.asMap());
}

@GwtIncompatible // threads
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";

final AtomicLong sum = new AtomicLong();
final AtomicLongMap<String> map = AtomicLongMap.create();

ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
for (int i = 0; i < nTasks; i++) {
@SuppressWarnings("unused") // go/futurereturn-lsc
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
int behavior = random.nextInt(10);
switch (behavior) {
case 0:
map.incrementAndGet(key);
threadSum++;
break;
case 1:
map.decrementAndGet(key);
threadSum--;
break;
case 2:
map.addAndGet(key, delta);
threadSum += delta;
break;
case 3:
map.getAndIncrement(key);
threadSum++;
break;
case 4:
map.getAndDecrement(key);
threadSum--;
break;
case 5:
map.getAndAdd(key, delta);
threadSum += delta;
break;
case 6:
long oldValue = map.put(key, delta);
threadSum += delta - oldValue;
break;
case 7:
oldValue = map.get(key);
if (map.replace(key, oldValue, delta)) {
threadSum += delta - oldValue;
}
break;
case 8:
oldValue = map.remove(key);
threadSum -= oldValue;
break;
case 9:
oldValue = map.get(key);
if (map.remove(key, oldValue)) {
threadSum -= oldValue;
}
break;
default:
throw new AssertionError();
}
}
sum.addAndGet(threadSum);
}
});
}

threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));

assertEquals(sum.get(), map.get(key));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public void testTransitionRace() throws TimeoutException {
}
ServiceManager manager = new ServiceManager(services);
manager.startAsync().awaitHealthy();
manager.stopAsync().awaitStopped(1, TimeUnit.SECONDS);
manager.stopAsync().awaitStopped(10, TimeUnit.SECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class SimpleTimeLimiterTest extends TestCase {

private static final long DELAY_MS = 50;
private static final long ENOUGH_MS = 500;
private static final long ENOUGH_MS = 10000;
private static final long NOT_ENOUGH_MS = 5;

private static final String GOOD_CALLABLE_RESULT = "good callable result";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testRegularFutureInterrupted() throws ExecutionException {

assertFalse(Thread.interrupted());
try {
delayedFuture.get(10000, TimeUnit.MILLISECONDS);
delayedFuture.get(20000, TimeUnit.MILLISECONDS);
fail("expected to be interrupted");
} catch (InterruptedException expected) {
} catch (TimeoutException e) {
Expand Down

0 comments on commit e3c1457

Please sign in to comment.