aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar olaola <olaola@google.com>2017-12-11 07:53:15 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-11 07:57:24 -0800
commita22d0e9c14e58b29d81f5a83bdcc6e5fce52eafe (patch)
tree305828b0cc64d6b9564b23ca311704abde8a9335 /src/test/java/com/google/devtools/build
parent180d25660cc5b1272497e30a1cdc494ac5eadf77 (diff)
Fix: uploading artifacts of failed actions to remote cache stopped working.
To reproduce: run a failing test with --experimental_remote_spawn_cache or with --spawn_strategy=remote and no executor. Expected: test log is uploaded. Desired behavior: - regardless of whether a spawn is cacheable or not, its artifacts should be uploaded to the remote cache. - the spawn result should only be set if the spawn is cacheable *and* the action succeeded. - when executing remotely, the do_not_cache field should be set for non-cacheable spawns, and the remote execution engine should respect it. This CL contains multiple fixes to ensure the above behaviors, and adds a few tests, both end to end and unit tests. Important behavior change: it is no longer assumed that non-cacheable spawns should use a NO_CACHE SpawnCache! The appropriate test case was removed. Instead, an assumption was added that all implementations of SpawnCache should respect the Spawns.mayBeCached(spawn) property. Currently, only NO_CACHE and RemoteSpawnCache exist, and they (now) support it. TESTED=remote build execution backend. WANT_LGTM: philwo,buchgr RELNOTES: None PiperOrigin-RevId: 178617937
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java19
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java40
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java12
3 files changed, 47 insertions, 24 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 3547e31ac6..986053fee9 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
@@ -167,23 +167,4 @@ public class AbstractSpawnStrategyTest {
verify(spawnRunner).exec(any(Spawn.class), any(SpawnExecutionPolicy.class));
verify(entry).store(eq(result), any(Collection.class));
}
-
- @Test
- public void testTagNoCache() throws Exception {
- SpawnCache cache = mock(SpawnCache.class);
- when(actionExecutionContext.getContext(eq(SpawnCache.class))).thenReturn(cache);
- when(actionExecutionContext.getExecRoot()).thenReturn(fs.getPath("/execroot"));
- when(spawnRunner.exec(any(Spawn.class), any(SpawnExecutionPolicy.class)))
- .thenReturn(new SpawnResult.Builder().setStatus(Status.SUCCESS).build());
-
- 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.
- verify(cache, never()).lookup(any(Spawn.class), any(SpawnExecutionPolicy.class));
- }
}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
index 7ac5cfa190..65c7d88960 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.actions.ActionInputFileCache;
import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
+import com.google.devtools.build.lib.actions.ExecutionRequirements;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.actions.SimpleSpawn;
import com.google.devtools.build.lib.actions.SpawnResult;
@@ -264,6 +265,45 @@ public class RemoteSpawnCacheTest {
}
@Test
+ public void noCacheSpawns() throws Exception {
+ // Checks that spawns that have mayBeCached false are not looked up in the remote cache,
+ // and also that their result is not uploaded to the remote cache. The artifacts, however,
+ // are uploaded.
+ SimpleSpawn uncacheableSpawn = new SimpleSpawn(
+ new FakeOwner("foo", "bar"),
+ /*arguments=*/ ImmutableList.of(),
+ /*environment=*/ ImmutableMap.of(),
+ ImmutableMap.of(ExecutionRequirements.NO_CACHE, ""),
+ /*inputs=*/ ImmutableList.of(),
+ /*outputs=*/ ImmutableList.<ActionInput>of(),
+ ResourceSet.ZERO);
+ CacheHandle entry = cache.lookup(uncacheableSpawn, simplePolicy);
+ verify(remoteCache, never())
+ .getCachedActionResult(any(ActionKey.class));
+ assertThat(entry.hasResult()).isFalse();
+ SpawnResult result = new SpawnResult.Builder().setExitCode(0).setStatus(Status.SUCCESS).build();
+ ImmutableList<Path> outputFiles = ImmutableList.of(fs.getPath("/random/file"));
+ entry.store(result, outputFiles);
+ verify(remoteCache)
+ .upload(any(ActionKey.class), any(Path.class), eq(outputFiles), eq(outErr), eq(false));
+ }
+
+ @Test
+ public void noCacheSpawnsNoResultStore() throws Exception {
+ // Only successful action results are uploaded to the remote cache. The artifacts, however,
+ // are uploaded regardless.
+ CacheHandle entry = cache.lookup(simpleSpawn, simplePolicy);
+ verify(remoteCache).getCachedActionResult(any(ActionKey.class));
+ assertThat(entry.hasResult()).isFalse();
+ SpawnResult result =
+ new SpawnResult.Builder().setExitCode(1).setStatus(Status.NON_ZERO_EXIT).build();
+ ImmutableList<Path> outputFiles = ImmutableList.of(fs.getPath("/random/file"));
+ entry.store(result, outputFiles);
+ verify(remoteCache)
+ .upload(any(ActionKey.class), any(Path.class), eq(outputFiles), eq(outErr), eq(false));
+ }
+
+ @Test
public void printWarningIfUploadFails() throws Exception {
CacheHandle entry = cache.lookup(simpleSpawn, simplePolicy);
assertThat(entry.hasResult()).isFalse();
diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
index 31681906d8..730244d627 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
@@ -115,8 +115,9 @@ public class RemoteSpawnRunnerTest {
@Test
@SuppressWarnings("unchecked")
public void nonCachableSpawnsShouldNotBeCached_remote() throws Exception {
- // Test that if a spawn is marked "NO_CACHE" that it's neither fetched from a remote cache
- // nor uploaded to a remote cache. It should be executed remotely, however.
+ // Test that if a spawn is marked "NO_CACHE" then it's not fetched from a remote cache.
+ // It should be executed remotely, but marked non-cacheable to remote execution, so that
+ // the action result is not saved in the remote cache.
RemoteOptions options = Options.getDefaults(RemoteOptions.class);
options.remoteAcceptCached = true;
@@ -156,6 +157,7 @@ public class RemoteSpawnRunnerTest {
ArgumentCaptor<ExecuteRequest> requestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
verify(executor).executeRemotely(requestCaptor.capture());
assertThat(requestCaptor.getValue().getSkipCacheLookup()).isTrue();
+ assertThat(requestCaptor.getValue().getAction().getDoNotCache()).isTrue();
verify(cache, never())
.getCachedActionResult(any(ActionKey.class));
@@ -173,7 +175,7 @@ public class RemoteSpawnRunnerTest {
@SuppressWarnings("unchecked")
public void nonCachableSpawnsShouldNotBeCached_local() throws Exception {
// Test that if a spawn is executed locally, due to the local fallback, that its result is not
- // uploaded to the remote cache.
+ // uploaded to the remote cache. However, the artifacts should still be uploaded.
RemoteOptions options = Options.getDefaults(RemoteOptions.class);
options.remoteAcceptCached = true;
@@ -213,13 +215,13 @@ public class RemoteSpawnRunnerTest {
verify(cache, never())
.getCachedActionResult(any(ActionKey.class));
- verify(cache, never())
+ verify(cache)
.upload(
any(ActionKey.class),
any(Path.class),
any(Collection.class),
any(FileOutErr.class),
- any(Boolean.class));
+ eq(false));
}
@Test