use of com.google.devtools.build.skyframe.InvalidatingNodeVisitor.InvalidationType in project bazel by bazelbuild.
the class EagerInvalidatorTest method interruptThreadInReceiver.
@Test
public void interruptThreadInReceiver() throws Exception {
Random random = new Random(TestUtils.getRandomSeed());
int graphSize = 1000;
int tries = 5;
graph = new InMemoryGraphImpl();
SkyKey[] values = constructLargeGraph(graphSize);
eval(/*keepGoing=*/
false, values);
final Thread mainThread = Thread.currentThread();
for (int run = 0; run < tries; run++) {
Set<Pair<SkyKey, InvalidationType>> valuesToInvalidate = getValuesToInvalidate(values);
// Find how many invalidations will actually be enqueued for invalidation in the first round,
// so that we can interrupt before all of them are done.
int validValuesToDo = Sets.difference(valuesToInvalidate, state.getInvalidationsForTesting()).size();
for (Pair<SkyKey, InvalidationType> pair : state.getInvalidationsForTesting()) {
if (!isInvalidated(pair.first)) {
validValuesToDo++;
}
}
int countDownStart = validValuesToDo > 0 ? random.nextInt(validValuesToDo) : 0;
final CountDownLatch countDownToInterrupt = new CountDownLatch(countDownStart);
final DirtyTrackingProgressReceiver receiver = new DirtyTrackingProgressReceiver(new EvaluationProgressReceiver() {
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
countDownToInterrupt.countDown();
if (countDownToInterrupt.getCount() == 0) {
mainThread.interrupt();
// Wait for the main thread to be interrupted uninterruptibly, because the main
// thread is going to interrupt us, and we don't want to get into an interrupt
// fight. Only if we get interrupted without the main thread also being interrupted
// will this throw an InterruptedException.
TrackingAwaiter.INSTANCE.awaitLatchAndTrackExceptions(visitor.get().getInterruptionLatchForTestingOnly(), "Main thread was not interrupted");
}
}
@Override
public void enqueueing(SkyKey skyKey) {
throw new UnsupportedOperationException();
}
@Override
public void computed(SkyKey skyKey, long elapsedTimeNanos) {
throw new UnsupportedOperationException();
}
@Override
public void evaluated(SkyKey skyKey, Supplier<SkyValue> skyValueSupplier, EvaluationState state) {
throw new UnsupportedOperationException();
}
});
try {
invalidate(graph, receiver, Sets.newHashSet(Iterables.transform(valuesToInvalidate, Pair.<SkyKey, InvalidationType>firstFunction())).toArray(new SkyKey[0]));
assertThat(state.getInvalidationsForTesting()).isEmpty();
} catch (InterruptedException e) {
// Expected.
}
if (state.isEmpty()) {
// Ran out of values to invalidate.
break;
}
}
eval(/*keepGoing=*/
false, values);
}
Aggregations