diff options
author | 2016-06-23 19:07:36 +0000 | |
---|---|---|
committer | 2016-06-24 08:12:10 +0000 | |
commit | 353988a97bfef72151d7e45d4ab9bed1ea456071 (patch) | |
tree | 41d0468c2ff7f00f9b18a73e4e81efa43a8c9397 /src/test/java/com/google/devtools | |
parent | 1c88f9cfafcd7f8856066a0ca4531ca2fc92c5bd (diff) |
Add test in GraphConcurrencyTest for concurrent createIfAbsent and get calls.
--
MOS_MIGRATED_REVID=125703258
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r-- | src/test/java/com/google/devtools/build/skyframe/GraphConcurrencyTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
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<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 |