aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-09-26 11:47:24 -0400
committerGravatar John Cater <jcater@google.com>2017-09-27 10:00:44 -0400
commit940ce20bb6045a8b0a09856f312991ba48ef2a7c (patch)
tree6733756468a318a05b5f4f9c17a05c9c5d85ef09 /src/test
parent95ce534f9f2cd1d43f8e0eb750fc61531bbb433f (diff)
Ensure that SpawnResults make their way back to the SpawnActions that caused them to be created.
RELNOTES: None. PiperOrigin-RevId: 170058295
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java b/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java
index 800749db2b..53ab069b1b 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java
@@ -34,6 +34,7 @@ import com.google.devtools.build.lib.testutil.TestSpec;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import java.util.Collection;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -67,10 +68,15 @@ public class AbstractSpawnStrategyTest {
public void testZeroExit() throws Exception {
when(actionExecutionContext.getContext(eq(SpawnCache.class))).thenReturn(SpawnCache.NO_CACHE);
when(actionExecutionContext.getExecRoot()).thenReturn(fs.getPath("/execroot"));
+ SpawnResult spawnResult = new SpawnResult.Builder().setStatus(Status.SUCCESS).build();
when(spawnRunner.exec(any(Spawn.class), any(SpawnExecutionPolicy.class)))
- .thenReturn(new SpawnResult.Builder().setStatus(Status.SUCCESS).build());
+ .thenReturn(spawnResult);
+
+ Set<SpawnResult> spawnResults = new TestedSpawnStrategy(spawnRunner)
+ .exec(SIMPLE_SPAWN, actionExecutionContext);
+
+ assertThat(spawnResults).containsExactly(spawnResult);
- new TestedSpawnStrategy(spawnRunner).exec(SIMPLE_SPAWN, actionExecutionContext);
// Must only be called exactly once.
verify(spawnRunner).exec(any(Spawn.class), any(SpawnExecutionPolicy.class));
}
@@ -84,6 +90,7 @@ public class AbstractSpawnStrategyTest {
.thenReturn(result);
try {
+ // Ignoring the Set<SpawnResult> return value.
new TestedSpawnStrategy(spawnRunner).exec(SIMPLE_SPAWN, actionExecutionContext);
fail("Expected SpawnExecException");
} catch (SpawnExecException e) {
@@ -96,13 +103,15 @@ public class AbstractSpawnStrategyTest {
@Test
public void testCacheHit() throws Exception {
SpawnCache cache = mock(SpawnCache.class);
- SpawnResult result = new SpawnResult.Builder().setStatus(Status.SUCCESS).build();
+ SpawnResult spawnResult = new SpawnResult.Builder().setStatus(Status.SUCCESS).build();
when(cache.lookup(any(Spawn.class), any(SpawnExecutionPolicy.class)))
- .thenReturn(SpawnCache.success(result));
+ .thenReturn(SpawnCache.success(spawnResult));
when(actionExecutionContext.getContext(eq(SpawnCache.class))).thenReturn(cache);
when(actionExecutionContext.getExecRoot()).thenReturn(fs.getPath("/execroot"));
- new TestedSpawnStrategy(spawnRunner).exec(SIMPLE_SPAWN, actionExecutionContext);
+ Set<SpawnResult> spawnResults = new TestedSpawnStrategy(spawnRunner)
+ .exec(SIMPLE_SPAWN, actionExecutionContext);
+ assertThat(spawnResults).containsExactly(spawnResult);
verify(spawnRunner, never()).exec(any(Spawn.class), any(SpawnExecutionPolicy.class));
}
@@ -117,13 +126,18 @@ public class AbstractSpawnStrategyTest {
when(actionExecutionContext.getContext(eq(SpawnCache.class))).thenReturn(cache);
when(actionExecutionContext.getExecRoot()).thenReturn(fs.getPath("/execroot"));
- SpawnResult result = new SpawnResult.Builder().setStatus(Status.SUCCESS).build();
- when(spawnRunner.exec(any(Spawn.class), any(SpawnExecutionPolicy.class))).thenReturn(result);
+ SpawnResult spawnResult = new SpawnResult.Builder().setStatus(Status.SUCCESS).build();
+ when(spawnRunner.exec(any(Spawn.class), any(SpawnExecutionPolicy.class)))
+ .thenReturn(spawnResult);
+
+ Set<SpawnResult> spawnResults = new TestedSpawnStrategy(spawnRunner)
+ .exec(SIMPLE_SPAWN, actionExecutionContext);
+
+ assertThat(spawnResults).containsExactly(spawnResult);
- new TestedSpawnStrategy(spawnRunner).exec(SIMPLE_SPAWN, actionExecutionContext);
// Must only be called exactly once.
verify(spawnRunner).exec(any(Spawn.class), any(SpawnExecutionPolicy.class));
- verify(entry).store(eq(result), any(Collection.class));
+ verify(entry).store(eq(spawnResult), any(Collection.class));
}
@SuppressWarnings("unchecked")
@@ -141,6 +155,7 @@ public class AbstractSpawnStrategyTest {
when(spawnRunner.exec(any(Spawn.class), any(SpawnExecutionPolicy.class))).thenReturn(result);
try {
+ // Ignoring the Set<SpawnResult> return value.
new TestedSpawnStrategy(spawnRunner).exec(SIMPLE_SPAWN, actionExecutionContext);
fail("Expected SpawnExecException");
} catch (SpawnExecException e) {
@@ -161,7 +176,9 @@ public class AbstractSpawnStrategyTest {
Spawn uncacheableSpawn =
new SpawnBuilder("/bin/echo", "Hi").withExecutionInfo("no-cache", "").build();
+
new TestedSpawnStrategy(spawnRunner).exec(uncacheableSpawn, actionExecutionContext);
+
// Must only be called exactly once.
verify(spawnRunner).exec(any(Spawn.class), any(SpawnExecutionPolicy.class));
// Must not be called.