diff options
author | olaola <olaola@google.com> | 2017-10-20 09:48:56 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-10-20 14:04:05 +0200 |
commit | ba8b0b3273ace313d35e9917c8116bab6386c6cc (patch) | |
tree | 1517f00aaa78fad053a78c52902fec422b56483f /src/test/java/com/google/devtools/build/lib | |
parent | 0db6559e3ccab6d33f13f25e9b5bea9e02415ac6 (diff) |
Properly attaching context for remote uploads in RemoteSpawnCache.
Fixes #3930. Also added tests.
TESTED=added tests
RELNOTES: Fixing regression to --experimental_remote_spawn_cache
PiperOrigin-RevId: 172852740
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java | 40 |
1 files changed, 39 insertions, 1 deletions
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 215f2b56a9..3295df658c 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 @@ -53,6 +53,7 @@ import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.common.options.Options; import com.google.devtools.remoteexecution.v1test.ActionResult; import com.google.devtools.remoteexecution.v1test.Command; +import com.google.devtools.remoteexecution.v1test.RequestMetadata; import java.io.IOException; import java.time.Duration; import java.util.Collection; @@ -62,7 +63,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; /** Tests for {@link RemoteSpawnCache}. */ @RunWith(JUnit4.class) @@ -176,7 +180,29 @@ public class RemoteSpawnCacheTest { @Test public void cacheHit() throws Exception { ActionResult actionResult = ActionResult.getDefaultInstance(); - when(remoteCache.getCachedActionResult(any(ActionKey.class))).thenReturn(actionResult); + when(remoteCache.getCachedActionResult(any(ActionKey.class))) + .thenAnswer( + new Answer<ActionResult>() { + @Override + public ActionResult answer(InvocationOnMock invocation) { + RequestMetadata meta = TracingMetadataUtils.fromCurrentContext(); + assertThat(meta.getCorrelatedInvocationsId()).isEqualTo("build-req-id"); + assertThat(meta.getToolInvocationId()).isEqualTo("command-id"); + return actionResult; + } + }); + Mockito.doAnswer( + new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) { + RequestMetadata meta = TracingMetadataUtils.fromCurrentContext(); + assertThat(meta.getCorrelatedInvocationsId()).isEqualTo("build-req-id"); + assertThat(meta.getToolInvocationId()).isEqualTo("command-id"); + return null; + } + }) + .when(remoteCache) + .download(actionResult, execRoot, outErr); CacheHandle entry = cache.lookup(simpleSpawn, simplePolicy); assertThat(entry.hasResult()).isTrue(); @@ -209,6 +235,18 @@ public class RemoteSpawnCacheTest { assertThat(entry.hasResult()).isFalse(); SpawnResult result = new SpawnResult.Builder().setExitCode(0).setStatus(Status.SUCCESS).build(); ImmutableList<Path> outputFiles = ImmutableList.of(fs.getPath("/random/file")); + Mockito.doAnswer( + new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) { + RequestMetadata meta = TracingMetadataUtils.fromCurrentContext(); + assertThat(meta.getCorrelatedInvocationsId()).isEqualTo("build-req-id"); + assertThat(meta.getToolInvocationId()).isEqualTo("command-id"); + return null; + } + }) + .when(remoteCache) + .upload(any(ActionKey.class), any(Path.class), eq(outputFiles), eq(outErr), eq(true)); entry.store(result, outputFiles); verify(remoteCache) .upload(any(ActionKey.class), any(Path.class), eq(outputFiles), eq(outErr), eq(true)); |