From 353988a97bfef72151d7e45d4ab9bed1ea456071 Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Thu, 23 Jun 2016 19:07:36 +0000 Subject: Add test in GraphConcurrencyTest for concurrent createIfAbsent and get calls. -- MOS_MIGRATED_REVID=125703258 --- .../build/skyframe/GraphConcurrencyTest.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/test/java/com/google/devtools') 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 26cb2818b3..a0580e2479 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 @@ public abstract class GraphConcurrencyTest { } } + @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 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 -- cgit v1.2.3