aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/exec
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-12-06 20:02:12 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-06 20:04:21 -0800
commit3ebb3d9d5010eee380f042fe435f61b00f8087dd (patch)
tree5e2ab785f0ab44483c63dcc4205522e6a3e3e151 /src/test/java/com/google/devtools/build/lib/exec
parented5df5310063274b439a34f3886d9cb058cd565f (diff)
If a temporary directory name clashes in the LocalSpawnRunner, try generating another temporary directory name instead of throwing an exception.
RELNOTES: None. PiperOrigin-RevId: 178190769
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/exec')
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunnerTest.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunnerTest.java
index f7aa1d9ff3..554b66c3f9 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunnerTest.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.exec.local;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
@@ -60,6 +61,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.function.LongSupplier;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
@@ -571,4 +573,41 @@ public class LocalSpawnRunnerTest {
"/bin/echo",
"Hi!"));
}
+
+ @Test
+ public void testCreateActionTemp_exceptionIfUnableToCreateDir() throws IOException {
+ Path execRoot = fs.getPath("/execroot");
+ assertThat(execRoot.createDirectory()).isTrue();
+ assertThat(execRoot.exists()).isTrue();
+ execRoot.setWritable(false);
+
+ assertThrows(IOException.class, () -> LocalSpawnRunner.createActionTemp(execRoot, () -> 0));
+ }
+
+ @Test
+ public void testCreateActionTemp_retriesIfNameClashes() throws IOException {
+ Path execRoot = fs.getPath("/execroot");
+ assertThat(execRoot.createDirectory()).isTrue();
+ assertThat(execRoot.exists()).isTrue();
+
+ Path tempPath1 = LocalSpawnRunner.createActionTemp(execRoot, () -> 0);
+ Path tempPath2 = LocalSpawnRunner.createActionTemp(execRoot, new IncreasingSequenceSupplier(0));
+
+ assertThat(tempPath1).isNotEqualTo(tempPath2);
+ assertThat(tempPath1.exists()).isTrue();
+ assertThat(tempPath2.exists()).isTrue();
+ }
+
+ private static class IncreasingSequenceSupplier implements LongSupplier {
+ private long currentElement;
+
+ public IncreasingSequenceSupplier(long startingElement) {
+ this.currentElement = startingElement;
+ }
+
+ @Override
+ public long getAsLong() {
+ return this.currentElement++;
+ }
+ }
}