Add test in GraphConcurrencyTest for concurrent createIfAbsent and get calls.
--
MOS_MIGRATED_REVID=125703258
diff --git a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
index 26cb281..a0580e2 100644
--- a/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
+++ b/src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java
@@ -100,6 +100,44 @@
}
}
+ @Test
+ public void testCreateIfAbsentWithConcurrentGet() throws Exception {
+ final SkyKey key = key("foo");
+ int numThreads = 50;
+ final CountDownLatch startThreads = new CountDownLatch(1);
+ Runnable createRunnable =
+ new Runnable() {
+ @Override
+ public void run() {
+ TrackingAwaiter.INSTANCE.awaitLatchAndTrackExceptions(
+ startThreads, "threads not started");
+ graph.createIfAbsentBatch(ImmutableList.of(key));
+ }
+ };
+ Runnable noCreateRunnable =
+ new Runnable() {
+ @Override
+ public void run() {
+ TrackingAwaiter.INSTANCE.awaitLatchAndTrackExceptions(
+ startThreads, "threads not started");
+ graph.get(key);
+ }
+ };
+ List<Thread> threads = new ArrayList<>(2 * numThreads);
+ for (int i = 0; i < numThreads; i++) {
+ Thread createThread = new Thread(createRunnable);
+ createThread.start();
+ threads.add(createThread);
+ Thread noCreateThread = new Thread(noCreateRunnable);
+ noCreateThread.start();
+ threads.add(noCreateThread);
+ }
+ startThreads.countDown();
+ for (Thread thread : threads) {
+ thread.join();
+ }
+ }
+
// Tests adding and removing Rdeps of a {@link NodeEntry} while a node transitions from
// not done to done.
@Test