Skip to content

Commit

Permalink
Fix TravisCI build
Browse files Browse the repository at this point in the history
Due to exceeding the 50 minute time limit, the support team was very
kind by extending it to 90 minutes. For now, merging this slow tests
into the same job for a fuller code coverage report.

Moving to a VM instance (vs container) for a beefer machine. This had
hung because some Guava tests block indefinitely on CountDownLatches.
Since I had switched their tests to use a pool instead of new threads,
thread starvation meant no progress could be made. Reverted to ad hoc
threads and added a timeout to the awaits().
  • Loading branch information
ben-manes committed Jul 7, 2017
1 parent 05e7f64 commit 9bf94d4
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 64 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
sudo: false
sudo: required

jdk:
- oraclejdk8
Expand All @@ -9,8 +9,7 @@ env:
- TERM=dumb
matrix:
- GROUP=analysis
- GROUP=unitTests
- GROUP=slowTests
- GROUP=tests

before_install:
- cp gradle.properties.ci gradle.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.lang.reflect.Constructor;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -38,6 +37,7 @@

import com.github.benmanes.caffeine.cache.Async.AsyncExpiry;
import com.github.benmanes.caffeine.testing.Awaits;
import com.github.benmanes.caffeine.testing.ConcurrentTestHarness;

/**
* @author [email protected] (Ben Manes)
Expand Down Expand Up @@ -81,7 +81,7 @@ public void getWhenSuccessful_success(CompletableFuture<?> future) {
public void getWhenSuccessful_success_async() {
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
AtomicInteger result = new AtomicInteger();
ForkJoinPool.commonPool().execute(() -> {
ConcurrentTestHarness.execute(() -> {
result.set(1);
result.set(Async.getWhenSuccessful(future));
});
Expand All @@ -94,7 +94,7 @@ public void getWhenSuccessful_success_async() {
public void getWhenSuccessful_fails(CompletableFuture<?> future) {
if ((future != null) && !future.isDone()) {
AtomicInteger result = new AtomicInteger();
ForkJoinPool.commonPool().execute(() -> {
ConcurrentTestHarness.execute(() -> {
result.set(1);
Object value = Async.getWhenSuccessful(future);
result.set((value == null) ? 2 : 3);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx384m -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=0 -noverify
org.gradle.daemon=false
org.gradle.jvmargs=-Xmx1024m -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=0 -noverify
org.gradle.daemon=true
nexusUsername=
nexusPassword=
8 changes: 4 additions & 4 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ext {
ehcache3: '3.3.1',
elasticSearch: '5.4.0',
expiringMap: '0.5.8',
jackrabbit: '1.7.2',
jackrabbit: '1.7.3',
jamm: '0.3.1',
javaObjectLayout: '0.8',
jmh: 1.19,
Expand All @@ -73,17 +73,17 @@ ext {
tcache: '1.0.3',
]
pluginVersions = [
buildscan: '1.7.4',
buildscan: '1.8',
buildscanRecipes: '0.2.0',
checkstyle: '8.0',
coveralls: '2.8.1',
coverity: '1.0.10',
errorProne: '0.0.10',
jacoco: '0.7.9',
jmh: '0.4.2',
jmhReport: '0.2.0',
jmhReport: '0.4.1',
nexus: '2.3.1',
pmd: '5.8.0',
pmd: '5.8.1',
propdeps: '0.0.10.RELEASE',
semanticVersioning: '1.1.0',
shadow: '2.0.1',
Expand Down
18 changes: 8 additions & 10 deletions guava/src/test/java/com/google/common/cache/CacheBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -329,7 +328,6 @@ public void testNullCache() {
}

@GwtIncompatible("QueuingRemovalListener")

public void testRemovalNotification_clear() throws InterruptedException {
// If a clear() happens while a computation is pending, we should not get a removal
// notification.
Expand All @@ -339,7 +337,7 @@ public void testRemovalNotification_clear() throws InterruptedException {
CacheLoader<String, String> computingFunction = new CacheLoader<String, String>() {
@Override public String load(String key) {
if (shouldWait.get()) {
Uninterruptibles.awaitUninterruptibly(computingLatch);
assertTrue(Uninterruptibles.awaitUninterruptibly(computingLatch, 300, TimeUnit.MINUTES));
}
return key;
}
Expand All @@ -356,19 +354,19 @@ public void testRemovalNotification_clear() throws InterruptedException {

final CountDownLatch computationStarted = new CountDownLatch(1);
final CountDownLatch computationComplete = new CountDownLatch(1);
ForkJoinPool.commonPool().execute(() -> {
new Thread(() -> {
computationStarted.countDown();
cache.getUnchecked("b");
computationComplete.countDown();
});
}).start();

// wait for the computingEntry to be created
computationStarted.await();
assertTrue(computationStarted.await(300, TimeUnit.MINUTES));
cache.invalidateAll();
// let the computation proceed
computingLatch.countDown();
// don't check cache.size() until we know the get("b") call is complete
computationComplete.await();
assertTrue(computationComplete.await(300, TimeUnit.MINUTES));

// At this point, the listener should be holding the seed value (a -> a), and the map should
// contain the computed value (b -> b), since the clear() happened before the computation
Expand Down Expand Up @@ -439,7 +437,7 @@ public void testRemovalNotification_clear_basher() throws InterruptedException {
Thread.yield();
}
cache.invalidateAll();
tasksFinished.await();
assertTrue(tasksFinished.await(300, TimeUnit.MINUTES));

// Check all of the removal notifications we received: they should have had correctly-associated
// keys and values. (An earlier bug saw removal notifications for in-progress computations,
Expand Down Expand Up @@ -525,7 +523,7 @@ public void testRemovalNotification_get_basher() throws InterruptedException {
}

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

// Since we're not doing any more cache operations, and the cache only expires/evicts when doing
// other operations, the cache and the removal queue won't change from this point on.
Expand Down Expand Up @@ -562,7 +560,7 @@ static final class DelayingIdentityLoader<T> extends CacheLoader<T, T> {

@Override public T load(T key) {
if (shouldWait.get()) {
Uninterruptibles.awaitUninterruptibly(delayLatch);
assertTrue(Uninterruptibles.awaitUninterruptibly(delayLatch, 300, TimeUnit.SECONDS));
}
return key;
}
Expand Down
61 changes: 30 additions & 31 deletions guava/src/test/java/com/google/common/cache/CacheLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -1871,7 +1870,7 @@ private static void testConcurrentLoadingDefault(Caffeine<Object, Object> builde
new CacheLoader<String, Object>() {
@Override public Object load(String key) {
callCount.incrementAndGet();
Uninterruptibles.awaitUninterruptibly(startSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(startSignal, 300, TimeUnit.SECONDS));
return result;
}
});
Expand Down Expand Up @@ -1900,7 +1899,7 @@ private static void testConcurrentLoadingNull(Caffeine<Object, Object> builder)
new CacheLoader<String, String>() {
@Override public String load(String key) {
callCount.incrementAndGet();
Uninterruptibles.awaitUninterruptibly(startSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(startSignal, 300, TimeUnit.SECONDS));
return null;
}
});
Expand Down Expand Up @@ -1938,7 +1937,7 @@ private static void testConcurrentLoadingUncheckedException(
new CacheLoader<String, String>() {
@Override public String load(String key) {
callCount.incrementAndGet();
Uninterruptibles.awaitUninterruptibly(startSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(startSignal, 300, TimeUnit.SECONDS));
throw e;
}
});
Expand Down Expand Up @@ -1979,7 +1978,7 @@ private static void testConcurrentLoadingCheckedException(
new CacheLoader<String, String>() {
@Override public String load(String key) throws Exception {
callCount.incrementAndGet();
Uninterruptibles.awaitUninterruptibly(startSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(startSignal, 300, TimeUnit.SECONDS));
throw e;
}
});
Expand Down Expand Up @@ -2055,7 +2054,7 @@ private static <K> List<Object> doConcurrentGet(final LoadingCache<K, ?> cache,
}
}
gettersStartedSignal.countDown();
gettersComplete.await();
assertTrue(gettersComplete.await(300, TimeUnit.SECONDS));

List<Object> resultList = Lists.newArrayListWithExpectedSize(nThreads);
for (int i = 0; i < nThreads; i++) {
Expand All @@ -2076,7 +2075,7 @@ public void testAsMapDuringLoading() throws InterruptedException, ExecutionExcep
@Override
public String load(String key) {
getStartedSignal.countDown();
Uninterruptibles.awaitUninterruptibly(letGetFinishSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(letGetFinishSignal, 300, TimeUnit.SECONDS));
return key + suffix;
}
};
Expand All @@ -2090,16 +2089,16 @@ public String load(String key) {
assertFalse(map.containsKey(getKey));
assertSame(refreshKey, map.get(refreshKey));

ForkJoinPool.commonPool().execute(() -> {
new Thread(() -> {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
});
ForkJoinPool.commonPool().execute(() -> {
}).start();
new Thread(() -> {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
});
}).start();

getStartedSignal.await();
assertTrue(getStartedSignal.await(300, TimeUnit.SECONDS));

// computation is in progress; asMap shouldn't have changed
assertEquals(1, map.size());
Expand All @@ -2108,7 +2107,7 @@ public String load(String key) {

// let computation complete
letGetFinishSignal.countDown();
getFinishedSignal.await();
assertTrue(getFinishedSignal.await(300, TimeUnit.SECONDS));
checkNothingLogged();

// asMap view should have been updated
Expand All @@ -2131,7 +2130,7 @@ public void disabled_testInvalidateDuringLoading() throws InterruptedException,
@Override
public String load(String key) {
computationStarted.countDown();
Uninterruptibles.awaitUninterruptibly(letGetFinishSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(letGetFinishSignal, 300, TimeUnit.SECONDS));
return key + suffix;
}
};
Expand All @@ -2141,24 +2140,24 @@ public String load(String key) {
ConcurrentMap<String,String> map = cache.asMap();
map.put(refreshKey, refreshKey);

ForkJoinPool.commonPool().execute(() -> {
new Thread(() -> {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
});
ForkJoinPool.commonPool().execute(() -> {
}).start();
new Thread(() -> {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
});
}).start();

computationStarted.await();
assertTrue(computationStarted.await(300, TimeUnit.SECONDS));
cache.invalidate(getKey);
cache.invalidate(refreshKey);
assertFalse(map.containsKey(getKey));
assertFalse(map.containsKey(refreshKey));

// let computation complete
letGetFinishSignal.countDown();
getFinishedSignal.await();
assertTrue(getFinishedSignal.await(300, TimeUnit.SECONDS));
checkNothingLogged();

// results should be visible
Expand All @@ -2183,7 +2182,7 @@ public void disabled_testInvalidateAndReloadDuringLoading()
@Override
public String load(String key) {
computationStarted.countDown();
Uninterruptibles.awaitUninterruptibly(letGetFinishSignal);
assertTrue(Uninterruptibles.awaitUninterruptibly(letGetFinishSignal, 300, TimeUnit.SECONDS));
return key + suffix;
}
};
Expand All @@ -2193,34 +2192,34 @@ public String load(String key) {
ConcurrentMap<String,String> map = cache.asMap();
map.put(refreshKey, refreshKey);

ForkJoinPool.commonPool().execute(() -> {
new Thread(() -> {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
});
ForkJoinPool.commonPool().execute(() -> {
}).start();
new Thread(() -> {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
});
}).start();

computationStarted.await();
assertTrue(computationStarted.await(300, TimeUnit.SECONDS));
cache.invalidate(getKey);
cache.invalidate(refreshKey);
assertFalse(map.containsKey(getKey));
assertFalse(map.containsKey(refreshKey));

// start new computations
ForkJoinPool.commonPool().execute(() -> {
new Thread(() -> {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
});
ForkJoinPool.commonPool().execute(() -> {
}).start();
new Thread(() -> {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
});
}).start();

// let computation complete
letGetFinishSignal.countDown();
getFinishedSignal.await();
assertTrue(getFinishedSignal.await(300, TimeUnit.SECONDS));
checkNothingLogged();

// results should be visible
Expand Down
3 changes: 2 additions & 1 deletion guava/src/test/java/jsr166/JSR166TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) {
@Override
protected String realCall() {
try {
latch.await();
assertTrue(latch.await(300, TimeUnit.SECONDS));
} catch (InterruptedException quittingTime) {}
return TEST_STRING;
}};
Expand Down
Loading

0 comments on commit 9bf94d4

Please sign in to comment.