buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.remote; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 17 | import static java.nio.charset.StandardCharsets.ISO_8859_1; |
michajlo | 660d17f | 2020-03-27 09:01:57 -0700 | [diff] [blame] | 18 | import static org.junit.Assert.assertThrows; |
Googler | 00cd262 | 2019-05-29 07:47:32 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.any; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.anyCollection; |
Googler | f11ea6f | 2020-02-04 09:43:01 -0800 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.eq; |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 22 | import static org.mockito.Mockito.doNothing; |
| 23 | import static org.mockito.Mockito.doThrow; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.inOrder; |
| 25 | import static org.mockito.Mockito.mock; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 26 | import static org.mockito.Mockito.never; |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 27 | import static org.mockito.Mockito.spy; |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 28 | import static org.mockito.Mockito.times; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 29 | import static org.mockito.Mockito.verify; |
Benjamin Peterson | f157053 | 2019-01-24 07:14:18 -0800 | [diff] [blame] | 30 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 31 | import static org.mockito.Mockito.when; |
| 32 | |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 33 | import build.bazel.remote.execution.v2.ActionResult; |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 34 | import build.bazel.remote.execution.v2.Digest; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 35 | import build.bazel.remote.execution.v2.ExecuteOperationMetadata; |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 36 | import build.bazel.remote.execution.v2.ExecuteRequest; |
| 37 | import build.bazel.remote.execution.v2.ExecuteResponse; |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 38 | import build.bazel.remote.execution.v2.ExecutedActionMetadata; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 39 | import build.bazel.remote.execution.v2.ExecutionStage.Value; |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 40 | import build.bazel.remote.execution.v2.LogFile; |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 41 | import com.google.common.collect.ClassToInstanceMap; |
| 42 | import com.google.common.collect.ImmutableClassToInstanceMap; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 43 | import com.google.common.collect.ImmutableList; |
| 44 | import com.google.common.collect.ImmutableMap; |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 45 | import com.google.common.collect.ImmutableSet; |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 46 | import com.google.common.eventbus.EventBus; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 47 | import com.google.common.io.ByteStreams; |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 48 | import com.google.common.util.concurrent.ListeningScheduledExecutorService; |
| 49 | import com.google.common.util.concurrent.MoreExecutors; |
buchgr | ff008f4 | 2018-06-02 14:13:43 -0700 | [diff] [blame] | 50 | import com.google.common.util.concurrent.SettableFuture; |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 51 | import com.google.devtools.build.lib.actions.ActionContext; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 52 | import com.google.devtools.build.lib.actions.ActionInput; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 53 | import com.google.devtools.build.lib.actions.Artifact; |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 54 | import com.google.devtools.build.lib.actions.ArtifactRoot; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 55 | import com.google.devtools.build.lib.actions.CommandLines.ParamFileActionInput; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 56 | import com.google.devtools.build.lib.actions.ExecutionRequirements; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 57 | import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 58 | import com.google.devtools.build.lib.actions.ResourceSet; |
| 59 | import com.google.devtools.build.lib.actions.SimpleSpawn; |
| 60 | import com.google.devtools.build.lib.actions.Spawn; |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 61 | import com.google.devtools.build.lib.actions.SpawnMetrics; |
ruperts | da40fbf | 2017-09-22 05:59:42 +0200 | [diff] [blame] | 62 | import com.google.devtools.build.lib.actions.SpawnResult; |
| 63 | import com.google.devtools.build.lib.actions.SpawnResult.Status; |
janakr | aea0560 | 2019-05-22 15:41:29 -0700 | [diff] [blame] | 64 | import com.google.devtools.build.lib.actions.util.ActionsTestUtil; |
buchgr | 559a07d | 2017-11-30 11:09:35 -0800 | [diff] [blame] | 65 | import com.google.devtools.build.lib.clock.JavaClock; |
ulfjack | e4cca14 | 2020-01-08 04:44:40 -0800 | [diff] [blame] | 66 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 67 | import com.google.devtools.build.lib.collect.nestedset.Order; |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 68 | import com.google.devtools.build.lib.events.Event; |
| 69 | import com.google.devtools.build.lib.events.EventKind; |
| 70 | import com.google.devtools.build.lib.events.Reporter; |
| 71 | import com.google.devtools.build.lib.events.StoredEventHandler; |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 72 | import com.google.devtools.build.lib.exec.AbstractSpawnStrategy; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 73 | import com.google.devtools.build.lib.exec.ExecutionOptions; |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 74 | import com.google.devtools.build.lib.exec.RemoteLocalFallbackRegistry; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 75 | import com.google.devtools.build.lib.exec.SpawnRunner; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 76 | import com.google.devtools.build.lib.exec.SpawnRunner.ProgressStatus; |
tomlu | 29e306d | 2018-04-19 05:41:44 -0700 | [diff] [blame] | 77 | import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 78 | import com.google.devtools.build.lib.exec.util.FakeOwner; |
Jakob Buchgraber | 1846269 | 2019-11-06 04:34:16 -0800 | [diff] [blame] | 79 | import com.google.devtools.build.lib.remote.common.CacheNotFoundException; |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 80 | import com.google.devtools.build.lib.remote.common.OperationObserver; |
Jakob Buchgraber | 6056609 | 2019-11-11 06:28:22 -0800 | [diff] [blame] | 81 | import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 82 | import com.google.devtools.build.lib.remote.common.RemoteExecutionClient; |
Jakob Buchgraber | 75b7ed4 | 2019-03-27 10:27:13 -0700 | [diff] [blame] | 83 | import com.google.devtools.build.lib.remote.options.RemoteOptions; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 84 | import com.google.devtools.build.lib.remote.options.RemoteOutputsMode; |
Googler | 922d1e6 | 2018-03-05 14:49:00 -0800 | [diff] [blame] | 85 | import com.google.devtools.build.lib.remote.util.DigestUtil; |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 86 | import com.google.devtools.build.lib.remote.util.FakeSpawnExecutionContext; |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 87 | import com.google.devtools.build.lib.testutil.TestUtils; |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 88 | import com.google.devtools.build.lib.util.ExitCode; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 89 | import com.google.devtools.build.lib.util.io.FileOutErr; |
ccalvarin | bda12a1 | 2018-06-21 18:57:26 -0700 | [diff] [blame] | 90 | import com.google.devtools.build.lib.vfs.DigestHashFunction; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 91 | import com.google.devtools.build.lib.vfs.FileSystem; |
| 92 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
| 93 | import com.google.devtools.build.lib.vfs.Path; |
| 94 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 95 | import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; |
| 96 | import com.google.devtools.common.options.Options; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 97 | import com.google.longrunning.Operation; |
| 98 | import com.google.protobuf.Any; |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 99 | import com.google.protobuf.Timestamp; |
| 100 | import com.google.protobuf.util.Durations; |
| 101 | import com.google.protobuf.util.Timestamps; |
olaola | 2732df0 | 2018-03-16 08:48:13 -0700 | [diff] [blame] | 102 | import com.google.rpc.Code; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 103 | import java.io.IOException; |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 104 | import java.io.InputStream; |
| 105 | import java.nio.charset.StandardCharsets; |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 106 | import java.time.Duration; |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 107 | import java.util.List; |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 108 | import java.util.concurrent.Executors; |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 109 | import java.util.concurrent.TimeUnit; |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 110 | import javax.annotation.Nullable; |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 111 | import org.junit.After; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 112 | import org.junit.Before; |
| 113 | import org.junit.Test; |
| 114 | import org.junit.runner.RunWith; |
| 115 | import org.junit.runners.JUnit4; |
| 116 | import org.mockito.ArgumentCaptor; |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 117 | import org.mockito.InOrder; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 118 | import org.mockito.Mock; |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 119 | import org.mockito.Mockito; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 120 | import org.mockito.MockitoAnnotations; |
| 121 | |
| 122 | /** Tests for {@link com.google.devtools.build.lib.remote.RemoteSpawnRunner} */ |
| 123 | @RunWith(JUnit4.class) |
| 124 | public class RemoteSpawnRunnerTest { |
| 125 | |
| 126 | private static final ImmutableMap<String, String> NO_CACHE = |
| 127 | ImmutableMap.of(ExecutionRequirements.NO_CACHE, ""); |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 128 | private ListeningScheduledExecutorService retryService; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 129 | |
| 130 | private Path execRoot; |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 131 | private Path logDir; |
buchgr | 559a07d | 2017-11-30 11:09:35 -0800 | [diff] [blame] | 132 | private DigestUtil digestUtil; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 133 | private FakeActionInputFileCache fakeFileCache; |
| 134 | private FileOutErr outErr; |
| 135 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 136 | private RemoteOptions remoteOptions; |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 137 | |
Jakob Buchgraber | 6056609 | 2019-11-11 06:28:22 -0800 | [diff] [blame] | 138 | @Mock private RemoteExecutionCache cache; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 139 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 140 | @Mock private RemoteExecutionClient executor; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 141 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 142 | @Mock private SpawnRunner localRunner; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 143 | |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 144 | // The action key of the Spawn returned by newSimpleSpawn(). |
| 145 | private final String simpleActionId = |
| 146 | "eb45b20cc979d504f96b9efc9a08c48103c6f017afa09c0df5c70a5f92a98ea8"; |
| 147 | |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 148 | @Before |
| 149 | public final void setUp() throws Exception { |
| 150 | MockitoAnnotations.initMocks(this); |
ccalvarin | bda12a1 | 2018-06-21 18:57:26 -0700 | [diff] [blame] | 151 | digestUtil = new DigestUtil(DigestHashFunction.SHA256); |
| 152 | FileSystem fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 153 | execRoot = fs.getPath("/exec/root"); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 154 | logDir = fs.getPath("/server-logs"); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 155 | FileSystemUtils.createDirectoryAndParents(execRoot); |
| 156 | fakeFileCache = new FakeActionInputFileCache(execRoot); |
| 157 | |
| 158 | Path stdout = fs.getPath("/tmp/stdout"); |
| 159 | Path stderr = fs.getPath("/tmp/stderr"); |
| 160 | FileSystemUtils.createDirectoryAndParents(stdout.getParentDirectory()); |
| 161 | FileSystemUtils.createDirectoryAndParents(stderr.getParentDirectory()); |
| 162 | outErr = new FileOutErr(stdout, stderr); |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 163 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 164 | remoteOptions = Options.getDefaults(RemoteOptions.class); |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 165 | |
| 166 | retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 167 | } |
| 168 | |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 169 | @After |
| 170 | public void afterEverything() throws InterruptedException { |
George Gensure | f600b69 | 2018-07-10 14:13:50 -0700 | [diff] [blame] | 171 | retryService.shutdownNow(); |
michajlo | 0f99c3c | 2020-03-09 16:07:50 -0700 | [diff] [blame] | 172 | retryService.awaitTermination(TestUtils.WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Test |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 176 | public void nonCachableSpawnsShouldNotBeCached_remote() throws Exception { |
olaola | a22d0e9 | 2017-12-11 07:53:15 -0800 | [diff] [blame] | 177 | // Test that if a spawn is marked "NO_CACHE" then it's not fetched from a remote cache. |
| 178 | // It should be executed remotely, but marked non-cacheable to remote execution, so that |
| 179 | // the action result is not saved in the remote cache. |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 180 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 181 | remoteOptions.remoteAcceptCached = true; |
| 182 | remoteOptions.remoteLocalFallback = false; |
| 183 | remoteOptions.remoteUploadLocalResults = true; |
| 184 | remoteOptions.remoteResultCachePriority = 1; |
| 185 | remoteOptions.remoteExecutionPriority = 2; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 186 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 187 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 188 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 189 | ExecuteResponse succeeded = |
| 190 | ExecuteResponse.newBuilder() |
| 191 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 192 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 193 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 194 | .thenReturn(succeeded); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 195 | |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 196 | Spawn spawn = simpleSpawnWithExecutionInfo(NO_CACHE); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 197 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 198 | |
| 199 | runner.exec(spawn, policy); |
| 200 | |
| 201 | ArgumentCaptor<ExecuteRequest> requestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 202 | verify(executor).executeRemotely(requestCaptor.capture(), any(OperationObserver.class)); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 203 | assertThat(requestCaptor.getValue().getSkipCacheLookup()).isTrue(); |
olaola | fea6ab4 | 2018-12-20 08:47:00 -0800 | [diff] [blame] | 204 | assertThat(requestCaptor.getValue().getResultsCachePolicy().getPriority()).isEqualTo(1); |
olaola | 5c97dcb | 2018-12-21 10:40:43 -0800 | [diff] [blame] | 205 | assertThat(requestCaptor.getValue().getExecutionPolicy().getPriority()).isEqualTo(2); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 206 | // TODO(olaola): verify that the uploaded action has the doNotCache set. |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 207 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 208 | verify(cache, never()) |
| 209 | .downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false)); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 210 | verify(cache, never()).upload(any(), any(), any(), any(), any(), any()); |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 211 | verifyNoMoreInteractions(localRunner); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 212 | } |
| 213 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 214 | private FakeSpawnExecutionContext getSpawnContext(Spawn spawn) { |
janakr | 619dcf8 | 2020-09-22 14:08:59 -0700 | [diff] [blame] | 215 | AbstractSpawnStrategy fakeLocalStrategy = |
| 216 | new AbstractSpawnStrategy(execRoot, localRunner, /*verboseFailures=*/ true) {}; |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 217 | ClassToInstanceMap<ActionContext> actionContextRegistry = |
| 218 | ImmutableClassToInstanceMap.of(RemoteLocalFallbackRegistry.class, () -> fakeLocalStrategy); |
| 219 | return new FakeSpawnExecutionContext( |
| 220 | spawn, fakeFileCache, execRoot, outErr, actionContextRegistry); |
| 221 | } |
| 222 | |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 223 | @Test |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 224 | public void nonCachableSpawnsShouldNotBeCached_localFallback() throws Exception { |
| 225 | // Test that if a non-cachable spawn is executed locally due to the local fallback, |
| 226 | // that its result is not uploaded to the remote cache. |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 227 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 228 | remoteOptions.remoteAcceptCached = true; |
| 229 | remoteOptions.remoteLocalFallback = true; |
| 230 | remoteOptions.remoteUploadLocalResults = true; |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 231 | |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 232 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 233 | |
| 234 | // Throw an IOException to trigger the local fallback. |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 235 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 236 | .thenThrow(IOException.class); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 237 | |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 238 | Spawn spawn = simpleSpawnWithExecutionInfo(NO_CACHE); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 239 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 240 | |
| 241 | runner.exec(spawn, policy); |
| 242 | |
| 243 | verify(localRunner).exec(spawn, policy); |
Jakob Buchgraber | 5f4d699 | 2019-11-14 07:00:02 -0800 | [diff] [blame] | 244 | verify(cache).ensureInputsPresent(any(), any()); |
Benjamin Peterson | f157053 | 2019-01-24 07:14:18 -0800 | [diff] [blame] | 245 | verifyNoMoreInteractions(cache); |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 248 | @Test |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 249 | public void cachableSpawnsShouldBeCached_localFallback() throws Exception { |
| 250 | // Test that if a cachable spawn is executed locally due to the local fallback, |
| 251 | // that its result is uploaded to the remote cache. |
| 252 | |
| 253 | remoteOptions.remoteAcceptCached = true; |
| 254 | remoteOptions.remoteLocalFallback = true; |
| 255 | remoteOptions.remoteUploadLocalResults = true; |
| 256 | |
| 257 | RemoteSpawnRunner runner = spy(newSpawnRunner()); |
| 258 | |
| 259 | // Throw an IOException to trigger the local fallback. |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 260 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 261 | .thenThrow(IOException.class); |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 262 | |
| 263 | SpawnResult res = |
| 264 | new SpawnResult.Builder() |
| 265 | .setStatus(Status.SUCCESS) |
| 266 | .setExitCode(0) |
| 267 | .setRunnerName("test") |
| 268 | .build(); |
| 269 | when(localRunner.exec(any(Spawn.class), any(SpawnExecutionContext.class))).thenReturn(res); |
| 270 | |
| 271 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 272 | SpawnExecutionContext policy = getSpawnContext(spawn); |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 273 | |
| 274 | SpawnResult result = runner.exec(spawn, policy); |
| 275 | assertThat(result.exitCode()).isEqualTo(0); |
| 276 | assertThat(result.status()).isEqualTo(Status.SUCCESS); |
| 277 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 278 | verify(runner) |
| 279 | .execLocallyAndUpload( |
| 280 | eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); |
| 281 | verify(cache).upload(any(), any(), any(), any(), any(), any()); |
| 282 | } |
| 283 | |
| 284 | @Test |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 285 | public void failedLocalActionShouldNotBeUploaded() throws Exception { |
| 286 | // Test that the outputs of a locally executed action that failed are not uploaded. |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 287 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 288 | remoteOptions.remoteLocalFallback = true; |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 289 | remoteOptions.remoteUploadLocalResults = true; |
| 290 | |
| 291 | RemoteSpawnRunner runner = spy(newSpawnRunner()); |
| 292 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 293 | // Throw an IOException to trigger the local fallback. |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 294 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 295 | .thenThrow(IOException.class); |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 296 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 297 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 298 | SpawnExecutionContext policy = getSpawnContext(spawn); |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 299 | |
| 300 | SpawnResult res = Mockito.mock(SpawnResult.class); |
| 301 | when(res.exitCode()).thenReturn(1); |
| 302 | when(res.status()).thenReturn(Status.EXECUTION_FAILED); |
| 303 | when(localRunner.exec(eq(spawn), eq(policy))).thenReturn(res); |
| 304 | |
cpovirk | a4d3da6 | 2019-05-02 14:27:33 -0700 | [diff] [blame] | 305 | assertThat(runner.exec(spawn, policy)).isSameInstanceAs(res); |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 306 | |
| 307 | verify(localRunner).exec(eq(spawn), eq(policy)); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 308 | verify(runner) |
| 309 | .execLocallyAndUpload( |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 310 | eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 311 | verify(cache, never()).upload(any(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | 562fcf9 | 2017-07-27 12:51:13 +0200 | [diff] [blame] | 312 | } |
| 313 | |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 314 | @Test |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 315 | public void treatFailedCachedActionAsCacheMiss_local() throws Exception { |
| 316 | // Test that bazel treats failed cache action as a cache miss and attempts to execute action |
| 317 | // locally |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 318 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 319 | remoteOptions.remoteLocalFallback = true; |
| 320 | remoteOptions.remoteUploadLocalResults = true; |
| 321 | |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 322 | ActionResult failedAction = ActionResult.newBuilder().setExitCode(1).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 323 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 324 | .thenReturn(failedAction); |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 325 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 326 | RemoteSpawnRunner runner = spy(newSpawnRunner()); |
| 327 | // Throw an IOException to trigger the local fallback. |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 328 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 329 | .thenThrow(IOException.class); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 330 | |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 331 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 332 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 333 | |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 334 | SpawnResult succeeded = |
| 335 | new SpawnResult.Builder() |
| 336 | .setStatus(Status.SUCCESS) |
| 337 | .setExitCode(0) |
| 338 | .setRunnerName("test") |
| 339 | .build(); |
| 340 | when(localRunner.exec(eq(spawn), eq(policy))).thenReturn(succeeded); |
| 341 | |
| 342 | runner.exec(spawn, policy); |
| 343 | |
| 344 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 345 | verify(runner) |
| 346 | .execLocallyAndUpload( |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 347 | eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 348 | verify(cache).upload(any(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 349 | verify(cache, never()).download(any(ActionResult.class), any(Path.class), eq(outErr), any()); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Test |
| 353 | public void treatFailedCachedActionAsCacheMiss_remote() throws Exception { |
| 354 | // Test that bazel treats failed cache action as a cache miss and attempts to execute action |
| 355 | // remotely |
| 356 | |
| 357 | ActionResult failedAction = ActionResult.newBuilder().setExitCode(1).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 358 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 359 | .thenReturn(failedAction); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 360 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 361 | RemoteSpawnRunner runner = newSpawnRunner(); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 362 | |
| 363 | ExecuteResponse succeeded = |
| 364 | ExecuteResponse.newBuilder() |
| 365 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 366 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 367 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 368 | .thenReturn(succeeded); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 369 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 370 | SpawnExecutionContext policy = getSpawnContext(spawn); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 371 | |
| 372 | runner.exec(spawn, policy); |
| 373 | |
| 374 | ArgumentCaptor<ExecuteRequest> requestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 375 | verify(executor).executeRemotely(requestCaptor.capture(), any(OperationObserver.class)); |
ishikhman | 62f5458 | 2019-03-18 03:42:42 -0700 | [diff] [blame] | 376 | assertThat(requestCaptor.getValue().getSkipCacheLookup()).isTrue(); |
buchgr | 2efea9d | 2017-08-11 16:19:00 +0200 | [diff] [blame] | 377 | } |
| 378 | |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 379 | @Test |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 380 | public void printWarningIfCacheIsDown() throws Exception { |
| 381 | // If we try to upload to a local cache, that is down a warning should be printed. |
| 382 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 383 | remoteOptions.remoteUploadLocalResults = true; |
| 384 | remoteOptions.remoteLocalFallback = true; |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 385 | |
| 386 | Reporter reporter = new Reporter(new EventBus()); |
| 387 | StoredEventHandler eventHandler = new StoredEventHandler(); |
| 388 | reporter.addHandler(eventHandler); |
| 389 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 390 | RemoteSpawnRunner runner = newSpawnRunner(reporter); |
| 391 | // Trigger local fallback |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 392 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 393 | .thenThrow(new IOException()); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 394 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 395 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 396 | SpawnExecutionContext policy = getSpawnContext(spawn); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 397 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 398 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 399 | .thenThrow(new IOException("cache down")); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 400 | |
olaola | 7744b86 | 2017-09-18 23:04:33 +0200 | [diff] [blame] | 401 | doThrow(new IOException("cache down")) |
| 402 | .when(cache) |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 403 | .upload(any(), any(), any(), any(), any(), any()); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 404 | |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 405 | SpawnResult res = |
| 406 | new SpawnResult.Builder() |
| 407 | .setStatus(Status.SUCCESS) |
| 408 | .setExitCode(0) |
| 409 | .setRunnerName("test") |
| 410 | .build(); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 411 | when(localRunner.exec(eq(spawn), eq(policy))).thenReturn(res); |
| 412 | |
| 413 | assertThat(runner.exec(spawn, policy)).isEqualTo(res); |
| 414 | |
| 415 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 416 | |
| 417 | assertThat(eventHandler.getEvents()).hasSize(1); |
| 418 | |
| 419 | Event evt = eventHandler.getEvents().get(0); |
| 420 | assertThat(evt.getKind()).isEqualTo(EventKind.WARNING); |
| 421 | assertThat(evt.getMessage()).contains("fail"); |
| 422 | assertThat(evt.getMessage()).contains("upload"); |
| 423 | } |
| 424 | |
| 425 | @Test |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 426 | public void noRemoteExecutorFallbackFails() throws Exception { |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 427 | // Errors from the fallback runner should be propagated out of the remote runner. |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 428 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 429 | remoteOptions.remoteUploadLocalResults = true; |
| 430 | remoteOptions.remoteLocalFallback = true; |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 431 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 432 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 433 | // Trigger local fallback |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 434 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 435 | .thenThrow(new IOException()); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 436 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 437 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 438 | SpawnExecutionContext policy = getSpawnContext(spawn); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 439 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 440 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 441 | .thenReturn(null); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 442 | |
| 443 | IOException err = new IOException("local execution error"); |
| 444 | when(localRunner.exec(eq(spawn), eq(policy))).thenThrow(err); |
| 445 | |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 446 | IOException e = assertThrows(IOException.class, () -> runner.exec(spawn, policy)); |
cpovirk | a4d3da6 | 2019-05-02 14:27:33 -0700 | [diff] [blame] | 447 | assertThat(e).isSameInstanceAs(err); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 448 | |
| 449 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 450 | } |
| 451 | |
| 452 | @Test |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 453 | public void remoteCacheErrorFallbackFails() throws Exception { |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 454 | // Errors from the fallback runner should be propagated out of the remote runner. |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 455 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 456 | remoteOptions.remoteUploadLocalResults = true; |
| 457 | remoteOptions.remoteLocalFallback = true; |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 458 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 459 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 460 | // Trigger local fallback |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 461 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 462 | .thenThrow(new IOException()); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 463 | |
| 464 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 465 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 466 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 467 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 468 | .thenThrow(new IOException()); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 469 | |
| 470 | IOException err = new IOException("local execution error"); |
| 471 | when(localRunner.exec(eq(spawn), eq(policy))).thenThrow(err); |
| 472 | |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 473 | IOException e = assertThrows(IOException.class, () -> runner.exec(spawn, policy)); |
cpovirk | a4d3da6 | 2019-05-02 14:27:33 -0700 | [diff] [blame] | 474 | assertThat(e).isSameInstanceAs(err); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 475 | |
| 476 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 477 | } |
| 478 | |
| 479 | @Test |
| 480 | public void testLocalFallbackFailureRemoteExecutorFailure() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 481 | remoteOptions.remoteLocalFallback = true; |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 482 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 483 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 484 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 485 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 486 | .thenReturn(null); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 487 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 488 | .thenThrow(new IOException()); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 489 | |
| 490 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 491 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 492 | |
| 493 | IOException err = new IOException("local execution error"); |
| 494 | when(localRunner.exec(eq(spawn), eq(policy))).thenThrow(err); |
| 495 | |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 496 | IOException e = assertThrows(IOException.class, () -> runner.exec(spawn, policy)); |
cpovirk | a4d3da6 | 2019-05-02 14:27:33 -0700 | [diff] [blame] | 497 | assertThat(e).isSameInstanceAs(err); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 498 | |
| 499 | verify(localRunner).exec(eq(spawn), eq(policy)); |
| 500 | } |
| 501 | |
| 502 | @Test |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 503 | public void testHumanReadableServerLogsSavedForFailingAction() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 504 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 505 | Digest logDigest = digestUtil.computeAsUtf8("bla"); |
buchgr | ff008f4 | 2018-06-02 14:13:43 -0700 | [diff] [blame] | 506 | Path logPath = logDir.getRelative(simpleActionId).getRelative("logname"); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 507 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 508 | .thenReturn( |
| 509 | ExecuteResponse.newBuilder() |
| 510 | .putServerLogs( |
| 511 | "logname", |
| 512 | LogFile.newBuilder().setHumanReadable(true).setDigest(logDigest).build()) |
| 513 | .setResult(ActionResult.newBuilder().setExitCode(31).build()) |
| 514 | .build()); |
buchgr | ff008f4 | 2018-06-02 14:13:43 -0700 | [diff] [blame] | 515 | SettableFuture<Void> completed = SettableFuture.create(); |
| 516 | completed.set(null); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 517 | when(cache.downloadFile(eq(logPath), eq(logDigest))).thenReturn(completed); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 518 | |
| 519 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 520 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 521 | |
| 522 | SpawnResult res = runner.exec(spawn, policy); |
| 523 | assertThat(res.status()).isEqualTo(Status.NON_ZERO_EXIT); |
| 524 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 525 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 526 | verify(cache).downloadFile(eq(logPath), eq(logDigest)); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | @Test |
| 530 | public void testHumanReadableServerLogsSavedForFailingActionWithStatus() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 531 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 532 | Digest logDigest = digestUtil.computeAsUtf8("bla"); |
buchgr | ff008f4 | 2018-06-02 14:13:43 -0700 | [diff] [blame] | 533 | Path logPath = logDir.getRelative(simpleActionId).getRelative("logname"); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 534 | com.google.rpc.Status timeoutStatus = |
| 535 | com.google.rpc.Status.newBuilder().setCode(Code.DEADLINE_EXCEEDED.getNumber()).build(); |
| 536 | ExecuteResponse resp = |
| 537 | ExecuteResponse.newBuilder() |
| 538 | .putServerLogs( |
| 539 | "logname", LogFile.newBuilder().setHumanReadable(true).setDigest(logDigest).build()) |
| 540 | .setStatus(timeoutStatus) |
| 541 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 542 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Benjamin Peterson | 1532df0 | 2019-01-24 08:45:44 -0800 | [diff] [blame] | 543 | .thenThrow(new IOException(new ExecutionStatusException(resp.getStatus(), resp))); |
buchgr | ff008f4 | 2018-06-02 14:13:43 -0700 | [diff] [blame] | 544 | SettableFuture<Void> completed = SettableFuture.create(); |
| 545 | completed.set(null); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 546 | when(cache.downloadFile(eq(logPath), eq(logDigest))).thenReturn(completed); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 547 | |
| 548 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 549 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 550 | |
| 551 | SpawnResult res = runner.exec(spawn, policy); |
| 552 | assertThat(res.status()).isEqualTo(Status.TIMEOUT); |
| 553 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 554 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 555 | verify(cache).downloadFile(eq(logPath), eq(logDigest)); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | @Test |
| 559 | public void testNonHumanReadableServerLogsNotSaved() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 560 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 561 | |
| 562 | Digest logDigest = digestUtil.computeAsUtf8("bla"); |
| 563 | ActionResult result = ActionResult.newBuilder().setExitCode(31).build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 564 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 565 | .thenReturn( |
| 566 | ExecuteResponse.newBuilder() |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 567 | .putServerLogs("logname", LogFile.newBuilder().setDigest(logDigest).build()) |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 568 | .setResult(result) |
| 569 | .build()); |
| 570 | |
| 571 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 572 | FakeSpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 573 | SpawnResult res = runner.exec(spawn, policy); |
| 574 | assertThat(res.status()).isEqualTo(Status.NON_ZERO_EXIT); |
| 575 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 576 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 577 | verify(cache).download(eq(result), eq(execRoot), any(FileOutErr.class), any()); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 578 | verify(cache, never()).downloadFile(any(Path.class), any(Digest.class)); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | @Test |
| 582 | public void testServerLogsNotSavedForSuccessfulAction() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 583 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 584 | |
| 585 | Digest logDigest = digestUtil.computeAsUtf8("bla"); |
| 586 | ActionResult result = ActionResult.newBuilder().setExitCode(0).build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 587 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 588 | .thenReturn( |
| 589 | ExecuteResponse.newBuilder() |
| 590 | .putServerLogs( |
| 591 | "logname", |
| 592 | LogFile.newBuilder().setHumanReadable(true).setDigest(logDigest).build()) |
| 593 | .setResult(result) |
| 594 | .build()); |
| 595 | |
| 596 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 597 | FakeSpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 598 | |
| 599 | SpawnResult res = runner.exec(spawn, policy); |
| 600 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 601 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 602 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 603 | verify(cache).download(eq(result), eq(execRoot), any(FileOutErr.class), any()); |
olaola | f0aa55d | 2018-08-16 08:51:06 -0700 | [diff] [blame] | 604 | verify(cache, never()).downloadFile(any(Path.class), any(Digest.class)); |
olaola | bf326fa | 2018-03-21 11:22:12 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | @Test |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 608 | public void cacheDownloadFailureTriggersRemoteExecution() throws Exception { |
| 609 | // If downloading a cached action fails, remote execution should be tried. |
| 610 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 611 | RemoteSpawnRunner runner = newSpawnRunner(); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 612 | |
| 613 | ActionResult cachedResult = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 614 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 615 | .thenReturn(cachedResult); |
George Gensure | aeee3e0 | 2020-04-15 04:43:45 -0700 | [diff] [blame] | 616 | Exception downloadFailure = |
| 617 | new BulkTransferException(new CacheNotFoundException(Digest.getDefaultInstance())); |
George Gensure | a168a82 | 2018-08-21 12:17:07 -0700 | [diff] [blame] | 618 | doThrow(downloadFailure) |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 619 | .when(cache) |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 620 | .download(eq(cachedResult), any(Path.class), any(FileOutErr.class), any()); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 621 | ActionResult execResult = ActionResult.newBuilder().setExitCode(31).build(); |
| 622 | ExecuteResponse succeeded = ExecuteResponse.newBuilder().setResult(execResult).build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 623 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 624 | .thenReturn(succeeded); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 625 | doNothing().when(cache).download(eq(execResult), any(Path.class), any(FileOutErr.class), any()); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 626 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 627 | Spawn spawn = newSimpleSpawn(); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 628 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 629 | SpawnExecutionContext policy = getSpawnContext(spawn); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 630 | |
| 631 | SpawnResult res = runner.exec(spawn, policy); |
ulfjack | 32e7a1c | 2017-11-28 01:14:34 -0800 | [diff] [blame] | 632 | assertThat(res.status()).isEqualTo(Status.NON_ZERO_EXIT); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 633 | assertThat(res.exitCode()).isEqualTo(31); |
| 634 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 635 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Benjamin Peterson | 3ff87f7 | 2017-08-21 18:41:45 +0200 | [diff] [blame] | 636 | } |
| 637 | |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 638 | @Test |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 639 | public void resultsDownloadFailureTriggersRemoteExecutionWithSkipCacheLookup() throws Exception { |
| 640 | // If downloading an action result fails, remote execution should be retried |
| 641 | // with skip cache lookup enabled |
| 642 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 643 | RemoteSpawnRunner runner = newSpawnRunner(); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 644 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 645 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 646 | .thenReturn(null); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 647 | ActionResult cachedResult = ActionResult.newBuilder().setExitCode(0).build(); |
| 648 | ActionResult execResult = ActionResult.newBuilder().setExitCode(31).build(); |
| 649 | ExecuteResponse cachedResponse = |
| 650 | ExecuteResponse.newBuilder().setResult(cachedResult).setCachedResult(true).build(); |
| 651 | ExecuteResponse executedResponse = ExecuteResponse.newBuilder().setResult(execResult).build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 652 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 653 | .thenReturn(cachedResponse) |
| 654 | .thenReturn(executedResponse); |
George Gensure | aeee3e0 | 2020-04-15 04:43:45 -0700 | [diff] [blame] | 655 | Exception downloadFailure = |
| 656 | new BulkTransferException(new CacheNotFoundException(Digest.getDefaultInstance())); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 657 | doThrow(downloadFailure) |
| 658 | .when(cache) |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 659 | .download(eq(cachedResult), any(Path.class), any(FileOutErr.class), any()); |
| 660 | doNothing().when(cache).download(eq(execResult), any(Path.class), any(FileOutErr.class), any()); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 661 | |
| 662 | Spawn spawn = newSimpleSpawn(); |
| 663 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 664 | SpawnExecutionContext policy = getSpawnContext(spawn); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 665 | |
| 666 | SpawnResult res = runner.exec(spawn, policy); |
| 667 | assertThat(res.status()).isEqualTo(Status.NON_ZERO_EXIT); |
| 668 | assertThat(res.exitCode()).isEqualTo(31); |
| 669 | |
| 670 | ArgumentCaptor<ExecuteRequest> requestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 671 | verify(executor, times(2)) |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 672 | .executeRemotely(requestCaptor.capture(), any(OperationObserver.class)); |
George Gensure | da146d2 | 2019-03-26 03:17:32 -0700 | [diff] [blame] | 673 | List<ExecuteRequest> requests = requestCaptor.getAllValues(); |
| 674 | // first request should have been executed without skip cache lookup |
| 675 | assertThat(requests.get(0).getSkipCacheLookup()).isFalse(); |
| 676 | // second should have been executed with skip cache lookup |
| 677 | assertThat(requests.get(1).getSkipCacheLookup()).isTrue(); |
| 678 | } |
| 679 | |
| 680 | @Test |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 681 | public void testRemoteExecutionTimeout() throws Exception { |
| 682 | // If remote execution times out the SpawnResult status should be TIMEOUT. |
| 683 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 684 | remoteOptions.remoteLocalFallback = false; |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 685 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 686 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 687 | |
| 688 | ActionResult cachedResult = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 689 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 690 | .thenReturn(null); |
olaola | 2732df0 | 2018-03-16 08:48:13 -0700 | [diff] [blame] | 691 | ExecuteResponse resp = |
| 692 | ExecuteResponse.newBuilder() |
| 693 | .setResult(cachedResult) |
| 694 | .setStatus( |
| 695 | com.google.rpc.Status.newBuilder() |
| 696 | .setCode(Code.DEADLINE_EXCEEDED.getNumber()) |
| 697 | .build()) |
| 698 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 699 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Benjamin Peterson | 1532df0 | 2019-01-24 08:45:44 -0800 | [diff] [blame] | 700 | .thenThrow(new IOException(new ExecutionStatusException(resp.getStatus(), resp))); |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 701 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 702 | Spawn spawn = newSimpleSpawn(); |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 703 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 704 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 705 | |
| 706 | SpawnResult res = runner.exec(spawn, policy); |
| 707 | assertThat(res.status()).isEqualTo(Status.TIMEOUT); |
| 708 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 709 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 710 | verify(cache).download(eq(cachedResult), eq(execRoot), any(FileOutErr.class), any()); |
buchgr | 4763abc | 2017-08-30 14:37:21 +0200 | [diff] [blame] | 711 | } |
| 712 | |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 713 | @Test |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 714 | public void testRemoteExecutionTimeoutDoesNotTriggerFallback() throws Exception { |
| 715 | // If remote execution times out the SpawnResult status should be TIMEOUT, regardess of local |
| 716 | // fallback option. |
| 717 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 718 | remoteOptions.remoteLocalFallback = true; |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 719 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 720 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 721 | |
| 722 | ActionResult cachedResult = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 723 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 724 | .thenReturn(null); |
olaola | 2732df0 | 2018-03-16 08:48:13 -0700 | [diff] [blame] | 725 | ExecuteResponse resp = |
| 726 | ExecuteResponse.newBuilder() |
| 727 | .setResult(cachedResult) |
| 728 | .setStatus( |
| 729 | com.google.rpc.Status.newBuilder() |
| 730 | .setCode(Code.DEADLINE_EXCEEDED.getNumber()) |
| 731 | .build()) |
| 732 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 733 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Benjamin Peterson | 1532df0 | 2019-01-24 08:45:44 -0800 | [diff] [blame] | 734 | .thenThrow(new IOException(new ExecutionStatusException(resp.getStatus(), resp))); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 735 | |
| 736 | Spawn spawn = newSimpleSpawn(); |
| 737 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 738 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 739 | |
| 740 | SpawnResult res = runner.exec(spawn, policy); |
| 741 | assertThat(res.status()).isEqualTo(Status.TIMEOUT); |
| 742 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 743 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 744 | verify(cache).download(eq(cachedResult), eq(execRoot), any(FileOutErr.class), any()); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 745 | verify(localRunner, never()).exec(eq(spawn), eq(policy)); |
| 746 | } |
| 747 | |
| 748 | @Test |
| 749 | public void testRemoteExecutionCommandFailureDoesNotTriggerFallback() throws Exception { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 750 | remoteOptions.remoteLocalFallback = true; |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 751 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 752 | RemoteSpawnRunner runner = newSpawnRunner(); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 753 | |
| 754 | ActionResult cachedResult = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 755 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 756 | .thenReturn(null); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 757 | ExecuteResponse failed = |
| 758 | ExecuteResponse.newBuilder() |
| 759 | .setResult(ActionResult.newBuilder().setExitCode(33).build()) |
| 760 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 761 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 762 | .thenReturn(failed); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 763 | |
| 764 | Spawn spawn = newSimpleSpawn(); |
| 765 | |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 766 | SpawnExecutionContext policy = getSpawnContext(spawn); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 767 | |
| 768 | SpawnResult res = runner.exec(spawn, policy); |
ulfjack | 32e7a1c | 2017-11-28 01:14:34 -0800 | [diff] [blame] | 769 | assertThat(res.status()).isEqualTo(Status.NON_ZERO_EXIT); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 770 | assertThat(res.exitCode()).isEqualTo(33); |
| 771 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 772 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 773 | verify(cache, never()).download(eq(cachedResult), eq(execRoot), any(FileOutErr.class), any()); |
olaola | 9062271 | 2017-10-17 02:55:18 +0200 | [diff] [blame] | 774 | verify(localRunner, never()).exec(eq(spawn), eq(policy)); |
| 775 | } |
| 776 | |
| 777 | @Test |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 778 | public void testExitCode_executorfailure() throws Exception { |
| 779 | // If we get a failure due to the remote cache not working, the exit code should be |
| 780 | // ExitCode.REMOTE_ERROR. |
| 781 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 782 | remoteOptions.remoteLocalFallback = false; |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 783 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 784 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 785 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 786 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 787 | .thenReturn(null); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 788 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 789 | .thenThrow(new IOException("reasons")); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 790 | |
| 791 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 792 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 793 | |
Jakob Buchgraber | a79a4b6 | 2019-06-23 02:06:20 -0700 | [diff] [blame] | 794 | SpawnResult result = runner.exec(spawn, policy); |
| 795 | assertThat(result.exitCode()).isEqualTo(ExitCode.REMOTE_ERROR.getNumericExitCode()); |
janakr | df70135 | 2020-10-13 08:20:35 -0700 | [diff] [blame] | 796 | assertThat(result.getDetailMessage("", false, false)).contains("reasons"); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Test |
| 800 | public void testExitCode_executionfailure() throws Exception { |
| 801 | // If we get a failure due to the remote executor not working, the exit code should be |
| 802 | // ExitCode.REMOTE_ERROR. |
| 803 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 804 | remoteOptions.remoteLocalFallback = false; |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 805 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 806 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 807 | |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 808 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 809 | .thenThrow(new IOException("reasons")); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 810 | |
| 811 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 812 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 813 | |
Jakob Buchgraber | a79a4b6 | 2019-06-23 02:06:20 -0700 | [diff] [blame] | 814 | SpawnResult result = runner.exec(spawn, policy); |
| 815 | assertThat(result.exitCode()).isEqualTo(ExitCode.REMOTE_ERROR.getNumericExitCode()); |
janakr | df70135 | 2020-10-13 08:20:35 -0700 | [diff] [blame] | 816 | assertThat(result.getDetailMessage("", false, false)).contains("reasons"); |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 817 | } |
| 818 | |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 819 | @Test |
| 820 | public void testMaterializeParamFiles() throws Exception { |
tomlu | b5a727a | 2019-08-03 23:06:35 -0700 | [diff] [blame] | 821 | testParamFilesAreMaterializedForFlag("--materialize_param_files"); |
| 822 | } |
| 823 | |
| 824 | @Test |
| 825 | public void testMaterializeParamFilesIsImpliedBySubcommands() throws Exception { |
| 826 | testParamFilesAreMaterializedForFlag("--subcommands"); |
| 827 | } |
| 828 | |
tomlu | b5a727a | 2019-08-03 23:06:35 -0700 | [diff] [blame] | 829 | private void testParamFilesAreMaterializedForFlag(String flag) throws Exception { |
| 830 | ExecutionOptions executionOptions = Options.parse(ExecutionOptions.class, flag).getOptions(); |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 831 | executionOptions.materializeParamFiles = true; |
| 832 | RemoteSpawnRunner runner = |
| 833 | new RemoteSpawnRunner( |
| 834 | execRoot, |
| 835 | Options.getDefaults(RemoteOptions.class), |
| 836 | executionOptions, |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 837 | true, |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 838 | /*cmdlineReporter=*/ null, |
| 839 | "build-req-id", |
| 840 | "command-id", |
| 841 | cache, |
| 842 | executor, |
Jakob Buchgraber | 20342c7 | 2019-11-12 04:56:16 -0800 | [diff] [blame] | 843 | retryService, |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 844 | digestUtil, |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 845 | logDir, |
cushon | e79dfd4 | 2019-09-18 18:58:06 -0700 | [diff] [blame] | 846 | /* filesToDownload= */ ImmutableSet.of()); |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 847 | |
| 848 | ExecuteResponse succeeded = |
| 849 | ExecuteResponse.newBuilder() |
| 850 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 851 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 852 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 853 | .thenReturn(succeeded); |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 854 | |
| 855 | ImmutableList<String> args = ImmutableList.of("--foo", "--bar"); |
| 856 | ParamFileActionInput input = |
| 857 | new ParamFileActionInput( |
| 858 | PathFragment.create("out/param_file"), args, ParameterFileType.UNQUOTED, ISO_8859_1); |
| 859 | Spawn spawn = |
| 860 | new SimpleSpawn( |
janakr | 94ff760 | 2020-05-19 12:59:28 -0700 | [diff] [blame] | 861 | new FakeOwner("foo", "bar", "//dummy:label"), |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 862 | /*arguments=*/ ImmutableList.of(), |
| 863 | /*environment=*/ ImmutableMap.of(), |
| 864 | /*executionInfo=*/ ImmutableMap.of(), |
ulfjack | e4cca14 | 2020-01-08 04:44:40 -0800 | [diff] [blame] | 865 | /*inputs=*/ NestedSetBuilder.create(Order.STABLE_ORDER, input), |
| 866 | /*outputs=*/ ImmutableSet.<ActionInput>of(), |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 867 | ResourceSet.ZERO); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 868 | SpawnExecutionContext policy = getSpawnContext(spawn); |
tomlu | 09fe062 | 2018-06-19 12:55:39 -0700 | [diff] [blame] | 869 | SpawnResult res = runner.exec(spawn, policy); |
| 870 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 871 | Path paramFile = execRoot.getRelative("out/param_file"); |
| 872 | assertThat(paramFile.exists()).isTrue(); |
| 873 | try (InputStream inputStream = paramFile.getInputStream()) { |
| 874 | assertThat( |
| 875 | new String(ByteStreams.toByteArray(inputStream), StandardCharsets.UTF_8).split("\n")) |
| 876 | .asList() |
| 877 | .containsExactly("--foo", "--bar"); |
| 878 | } |
| 879 | } |
| 880 | |
olaola | 8afd0fb | 2018-10-30 08:36:29 -0700 | [diff] [blame] | 881 | @Test |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 882 | public void testDownloadMinimalOnCacheHit() throws Exception { |
| 883 | // arrange |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 884 | remoteOptions.remoteOutputsMode = RemoteOutputsMode.MINIMAL; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 885 | |
| 886 | ActionResult succeededAction = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 887 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 888 | .thenReturn(succeededAction); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 889 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 890 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 891 | |
| 892 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 893 | SpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 894 | |
| 895 | // act |
| 896 | SpawnResult result = runner.exec(spawn, policy); |
| 897 | assertThat(result.exitCode()).isEqualTo(0); |
| 898 | assertThat(result.status()).isEqualTo(Status.SUCCESS); |
| 899 | |
| 900 | // assert |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 901 | verify(cache) |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 902 | .downloadMinimal( |
| 903 | any(), eq(succeededAction), anyCollection(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 904 | verify(cache, never()).download(any(ActionResult.class), any(Path.class), eq(outErr), any()); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | @Test |
| 908 | public void testDownloadMinimalOnCacheMiss() throws Exception { |
| 909 | // arrange |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 910 | remoteOptions.remoteOutputsMode = RemoteOutputsMode.MINIMAL; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 911 | |
| 912 | ActionResult succeededAction = ActionResult.newBuilder().setExitCode(0).build(); |
| 913 | ExecuteResponse succeeded = ExecuteResponse.newBuilder().setResult(succeededAction).build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 914 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 915 | .thenReturn(succeeded); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 916 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 917 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 918 | |
| 919 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 920 | FakeSpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 921 | |
| 922 | // act |
| 923 | SpawnResult result = runner.exec(spawn, policy); |
| 924 | assertThat(result.exitCode()).isEqualTo(0); |
| 925 | assertThat(result.status()).isEqualTo(Status.SUCCESS); |
| 926 | |
| 927 | // assert |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 928 | verify(executor).executeRemotely(any(), any(OperationObserver.class)); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 929 | verify(cache) |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 930 | .downloadMinimal( |
| 931 | any(), eq(succeededAction), anyCollection(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 932 | verify(cache, never()).download(any(ActionResult.class), any(Path.class), eq(outErr), any()); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | @Test |
| 936 | public void testDownloadMinimalIoError() throws Exception { |
| 937 | // arrange |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 938 | remoteOptions.remoteOutputsMode = RemoteOutputsMode.MINIMAL; |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 939 | |
| 940 | ActionResult succeededAction = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 941 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 942 | .thenReturn(succeededAction); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 943 | IOException downloadFailure = new IOException("downloadMinimal failed"); |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 944 | when(cache.downloadMinimal(any(), any(), anyCollection(), any(), any(), any(), any(), any())) |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 945 | .thenThrow(downloadFailure); |
| 946 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 947 | RemoteSpawnRunner runner = newSpawnRunner(); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 948 | |
| 949 | Spawn spawn = newSimpleSpawn(); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 950 | FakeSpawnExecutionContext policy = getSpawnContext(spawn); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 951 | |
| 952 | // act |
Jakob Buchgraber | a79a4b6 | 2019-06-23 02:06:20 -0700 | [diff] [blame] | 953 | SpawnResult result = runner.exec(spawn, policy); |
| 954 | assertThat(result.getFailureMessage()).isEqualTo(downloadFailure.getMessage()); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 955 | |
| 956 | // assert |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 957 | verify(cache) |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 958 | .downloadMinimal( |
| 959 | any(), eq(succeededAction), anyCollection(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 960 | verify(cache, never()).download(any(ActionResult.class), any(Path.class), eq(outErr), any()); |
buchgr | d480c5f | 2019-04-03 00:53:34 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 963 | @Test |
| 964 | public void testDownloadTopLevel() throws Exception { |
| 965 | // arrange |
| 966 | RemoteOptions options = Options.getDefaults(RemoteOptions.class); |
| 967 | options.remoteOutputsMode = RemoteOutputsMode.TOPLEVEL; |
| 968 | |
janakr | 448f1cf | 2020-03-30 09:12:44 -0700 | [diff] [blame] | 969 | ArtifactRoot outputRoot = ArtifactRoot.asDerivedRoot(execRoot, "outs"); |
janakr | aea0560 | 2019-05-22 15:41:29 -0700 | [diff] [blame] | 970 | Artifact topLevelOutput = |
| 971 | ActionsTestUtil.createArtifact(outputRoot, outputRoot.getRoot().getRelative("foo.bin")); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 972 | |
| 973 | ActionResult succeededAction = ActionResult.newBuilder().setExitCode(0).build(); |
Jakob Buchgraber | 21577f2 | 2020-03-23 03:11:29 -0700 | [diff] [blame] | 974 | when(cache.downloadActionResult(any(ActionKey.class), /* inlineOutErr= */ eq(false))) |
| 975 | .thenReturn(succeededAction); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 976 | |
| 977 | RemoteSpawnRunner runner = newSpawnRunner(ImmutableSet.of(topLevelOutput)); |
| 978 | |
| 979 | Spawn spawn = newSimpleSpawn(topLevelOutput); |
schmitt | de9b955 | 2020-01-13 10:44:29 -0800 | [diff] [blame] | 980 | FakeSpawnExecutionContext policy = getSpawnContext(spawn); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 981 | |
| 982 | // act |
| 983 | SpawnResult result = runner.exec(spawn, policy); |
| 984 | assertThat(result.exitCode()).isEqualTo(0); |
| 985 | assertThat(result.status()).isEqualTo(Status.SUCCESS); |
| 986 | |
| 987 | // assert |
Jakob Buchgraber | d75b6cf | 2019-06-19 08:12:49 -0700 | [diff] [blame] | 988 | verify(cache).download(eq(succeededAction), any(Path.class), eq(outErr), any()); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 989 | verify(cache, never()) |
George Gensure | 3ef8fb9 | 2020-05-06 09:49:48 -0700 | [diff] [blame] | 990 | .downloadMinimal( |
| 991 | any(), eq(succeededAction), anyCollection(), any(), any(), any(), any(), any()); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 992 | } |
| 993 | |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 994 | @Test |
| 995 | public void accountingDisabledWithoutWorker() { |
| 996 | SpawnMetrics.Builder spawnMetrics = Mockito.mock(SpawnMetrics.Builder.class); |
| 997 | RemoteSpawnRunner.spawnMetricsAccounting( |
| 998 | spawnMetrics, ExecutedActionMetadata.getDefaultInstance()); |
| 999 | verifyNoMoreInteractions(spawnMetrics); |
| 1000 | } |
| 1001 | |
| 1002 | @Test |
| 1003 | public void accountingAddsDurationsForStages() { |
| 1004 | SpawnMetrics.Builder builder = |
Googler | 2b7e71a | 2020-06-04 01:32:01 -0700 | [diff] [blame] | 1005 | SpawnMetrics.Builder.forRemoteExec() |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 1006 | .setQueueTime(Duration.ofSeconds(1)) |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 1007 | .setSetupTime(Duration.ofSeconds(2)) |
| 1008 | .setExecutionWallTime(Duration.ofSeconds(2)) |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 1009 | .setProcessOutputsTime(Duration.ofSeconds(2)); |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 1010 | Timestamp queued = Timestamp.getDefaultInstance(); |
| 1011 | com.google.protobuf.Duration oneSecond = Durations.fromMillis(1000); |
| 1012 | Timestamp workerStart = Timestamps.add(queued, oneSecond); |
| 1013 | Timestamp executionStart = Timestamps.add(workerStart, oneSecond); |
| 1014 | Timestamp executionCompleted = Timestamps.add(executionStart, oneSecond); |
| 1015 | Timestamp outputUploadStart = Timestamps.add(executionCompleted, oneSecond); |
| 1016 | Timestamp outputUploadComplete = Timestamps.add(outputUploadStart, oneSecond); |
| 1017 | ExecutedActionMetadata executedMetadata = |
| 1018 | ExecutedActionMetadata.newBuilder() |
| 1019 | .setWorker("test worker") |
| 1020 | .setQueuedTimestamp(queued) |
| 1021 | .setWorkerStartTimestamp(workerStart) |
| 1022 | .setExecutionStartTimestamp(executionStart) |
| 1023 | .setExecutionCompletedTimestamp(executionCompleted) |
| 1024 | .setOutputUploadStartTimestamp(outputUploadStart) |
| 1025 | .setOutputUploadCompletedTimestamp(outputUploadComplete) |
| 1026 | .build(); |
| 1027 | RemoteSpawnRunner.spawnMetricsAccounting(builder, executedMetadata); |
| 1028 | SpawnMetrics spawnMetrics = builder.build(); |
| 1029 | // remote queue time is accumulated |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 1030 | assertThat(spawnMetrics.queueTime()).isEqualTo(Duration.ofSeconds(2)); |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 1031 | // setup time is substituted |
| 1032 | assertThat(spawnMetrics.setupTime()).isEqualTo(Duration.ofSeconds(1)); |
| 1033 | // execution time is unspecified, assume substituted |
| 1034 | assertThat(spawnMetrics.executionWallTime()).isEqualTo(Duration.ofSeconds(1)); |
Googler | d9aa8ae | 2020-05-20 00:56:28 -0700 | [diff] [blame] | 1035 | // ProcessOutputs time is unspecified, assume substituted |
| 1036 | assertThat(spawnMetrics.processOutputsTime()).isEqualTo(Duration.ofSeconds(1)); |
George Gensure | 7aa7498 | 2020-04-01 00:54:15 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1039 | @Test |
| 1040 | public void shouldReportExecutingStatusWithoutMetadata() throws Exception { |
| 1041 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 1042 | ExecuteResponse succeeded = |
| 1043 | ExecuteResponse.newBuilder() |
| 1044 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 1045 | .build(); |
| 1046 | |
| 1047 | Spawn spawn = newSimpleSpawn(); |
| 1048 | SpawnExecutionContext policy = mock(SpawnExecutionContext.class); |
| 1049 | when(policy.getTimeout()).thenReturn(Duration.ZERO); |
| 1050 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1051 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1052 | .thenAnswer( |
| 1053 | invocationOnMock -> { |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1054 | OperationObserver receiver = invocationOnMock.getArgument(1); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1055 | verify(policy, never()).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1056 | receiver.onNext(Operation.getDefaultInstance()); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1057 | return succeeded; |
| 1058 | }); |
| 1059 | |
| 1060 | SpawnResult res = runner.exec(spawn, policy); |
| 1061 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 1062 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1063 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1064 | InOrder reportOrder = inOrder(policy); |
| 1065 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.SCHEDULING), any(String.class)); |
| 1066 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1067 | } |
| 1068 | |
| 1069 | @Test |
| 1070 | public void shouldReportExecutingStatusAfterGotExecutingStageFromMetadata() throws Exception { |
| 1071 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 1072 | ExecuteResponse succeeded = |
| 1073 | ExecuteResponse.newBuilder() |
| 1074 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 1075 | .build(); |
| 1076 | |
| 1077 | Spawn spawn = newSimpleSpawn(); |
| 1078 | SpawnExecutionContext policy = mock(SpawnExecutionContext.class); |
| 1079 | when(policy.getTimeout()).thenReturn(Duration.ZERO); |
| 1080 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1081 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1082 | .thenAnswer( |
| 1083 | invocationOnMock -> { |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1084 | OperationObserver receiver = invocationOnMock.getArgument(1); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1085 | Operation queued = |
| 1086 | Operation.newBuilder() |
| 1087 | .setMetadata( |
| 1088 | Any.pack( |
| 1089 | ExecuteOperationMetadata.newBuilder().setStage(Value.QUEUED).build())) |
| 1090 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1091 | receiver.onNext(queued); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1092 | verify(policy, never()).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1093 | |
| 1094 | Operation executing = |
| 1095 | Operation.newBuilder() |
| 1096 | .setMetadata( |
| 1097 | Any.pack( |
| 1098 | ExecuteOperationMetadata.newBuilder() |
| 1099 | .setStage(Value.EXECUTING) |
| 1100 | .build())) |
| 1101 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1102 | receiver.onNext(executing); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1103 | |
| 1104 | return succeeded; |
| 1105 | }); |
| 1106 | |
| 1107 | SpawnResult res = runner.exec(spawn, policy); |
| 1108 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 1109 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1110 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1111 | InOrder reportOrder = inOrder(policy); |
| 1112 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.SCHEDULING), any(String.class)); |
| 1113 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1114 | } |
| 1115 | |
| 1116 | @Test |
Chi Wang | 0f26b17 | 2020-08-20 07:19:17 -0700 | [diff] [blame] | 1117 | public void shouldIgnoreInvalidMetadata() throws Exception { |
| 1118 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 1119 | ExecuteResponse succeeded = |
| 1120 | ExecuteResponse.newBuilder() |
| 1121 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 1122 | .build(); |
| 1123 | |
| 1124 | Spawn spawn = newSimpleSpawn(); |
| 1125 | SpawnExecutionContext policy = mock(SpawnExecutionContext.class); |
| 1126 | when(policy.getTimeout()).thenReturn(Duration.ZERO); |
| 1127 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1128 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | 0f26b17 | 2020-08-20 07:19:17 -0700 | [diff] [blame] | 1129 | .thenAnswer( |
| 1130 | invocationOnMock -> { |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1131 | OperationObserver receiver = invocationOnMock.getArgument(1); |
Chi Wang | 0f26b17 | 2020-08-20 07:19:17 -0700 | [diff] [blame] | 1132 | Operation operation = |
| 1133 | Operation.newBuilder() |
| 1134 | .setMetadata( |
| 1135 | // Anything that is not ExecutionOperationMetadata |
| 1136 | Any.pack(Operation.getDefaultInstance())) |
| 1137 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1138 | receiver.onNext(operation); |
Chi Wang | 0f26b17 | 2020-08-20 07:19:17 -0700 | [diff] [blame] | 1139 | return succeeded; |
| 1140 | }); |
| 1141 | |
| 1142 | SpawnResult res = runner.exec(spawn, policy); |
| 1143 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 1144 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1145 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Chi Wang | 0f26b17 | 2020-08-20 07:19:17 -0700 | [diff] [blame] | 1146 | InOrder reportOrder = inOrder(policy); |
| 1147 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.SCHEDULING), any(String.class)); |
| 1148 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1149 | } |
| 1150 | |
| 1151 | @Test |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1152 | public void shouldReportExecutingStatusIfNoExecutingStatusFromMetadata() throws Exception { |
| 1153 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 1154 | ExecuteResponse succeeded = |
| 1155 | ExecuteResponse.newBuilder() |
| 1156 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 1157 | .build(); |
| 1158 | |
| 1159 | Spawn spawn = newSimpleSpawn(); |
| 1160 | SpawnExecutionContext policy = mock(SpawnExecutionContext.class); |
| 1161 | when(policy.getTimeout()).thenReturn(Duration.ZERO); |
| 1162 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1163 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1164 | .thenAnswer( |
| 1165 | invocationOnMock -> { |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1166 | OperationObserver receiver = invocationOnMock.getArgument(1); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1167 | Operation completed = |
| 1168 | Operation.newBuilder() |
| 1169 | .setMetadata( |
| 1170 | Any.pack( |
| 1171 | ExecuteOperationMetadata.newBuilder() |
| 1172 | .setStage(Value.COMPLETED) |
| 1173 | .build())) |
| 1174 | .build(); |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1175 | receiver.onNext(completed); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1176 | return succeeded; |
| 1177 | }); |
| 1178 | |
| 1179 | SpawnResult res = runner.exec(spawn, policy); |
| 1180 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 1181 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1182 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1183 | InOrder reportOrder = inOrder(policy); |
| 1184 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.SCHEDULING), any(String.class)); |
| 1185 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1186 | } |
| 1187 | |
| 1188 | @Test |
| 1189 | public void shouldReportExecutingStatusEvenNoOperationFromServer() throws Exception { |
| 1190 | RemoteSpawnRunner runner = newSpawnRunner(); |
| 1191 | ExecuteResponse succeeded = |
| 1192 | ExecuteResponse.newBuilder() |
| 1193 | .setResult(ActionResult.newBuilder().setExitCode(0).build()) |
| 1194 | .build(); |
| 1195 | |
| 1196 | Spawn spawn = newSimpleSpawn(); |
| 1197 | SpawnExecutionContext policy = mock(SpawnExecutionContext.class); |
| 1198 | when(policy.getTimeout()).thenReturn(Duration.ZERO); |
| 1199 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1200 | when(executor.executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class))) |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1201 | .thenReturn(succeeded); |
| 1202 | |
| 1203 | SpawnResult res = runner.exec(spawn, policy); |
| 1204 | assertThat(res.status()).isEqualTo(Status.SUCCESS); |
| 1205 | |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1206 | verify(executor).executeRemotely(any(ExecuteRequest.class), any(OperationObserver.class)); |
Chi Wang | e8d356d | 2020-08-14 00:27:19 -0700 | [diff] [blame] | 1207 | InOrder reportOrder = inOrder(policy); |
| 1208 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.SCHEDULING), any(String.class)); |
| 1209 | reportOrder.verify(policy, times(1)).report(eq(ProgressStatus.EXECUTING), any(String.class)); |
| 1210 | } |
| 1211 | |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 1212 | private static Spawn newSimpleSpawn(Artifact... outputs) { |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 1213 | return simpleSpawnWithExecutionInfo(ImmutableMap.of(), outputs); |
| 1214 | } |
| 1215 | |
| 1216 | private static SimpleSpawn simpleSpawnWithExecutionInfo( |
| 1217 | ImmutableMap<String, String> executionInfo, Artifact... outputs) { |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 1218 | return new SimpleSpawn( |
janakr | 94ff760 | 2020-05-19 12:59:28 -0700 | [diff] [blame] | 1219 | new FakeOwner("foo", "bar", "//dummy:label"), |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1220 | /*arguments=*/ ImmutableList.of(), |
| 1221 | /*environment=*/ ImmutableMap.of(), |
Sergio Rodriguez Orellana | 8860c3e | 2019-07-25 01:12:58 -0700 | [diff] [blame] | 1222 | /*executionInfo=*/ executionInfo, |
ulfjack | e4cca14 | 2020-01-08 04:44:40 -0800 | [diff] [blame] | 1223 | /*inputs=*/ NestedSetBuilder.emptySet(Order.STABLE_ORDER), |
| 1224 | /*outputs=*/ ImmutableSet.copyOf(outputs), |
buchgr | a659135 | 2017-09-01 13:14:19 +0200 | [diff] [blame] | 1225 | ResourceSet.ZERO); |
| 1226 | } |
| 1227 | |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1228 | private RemoteSpawnRunner newSpawnRunner() { |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 1229 | return newSpawnRunner( |
| 1230 | /* verboseFailures= */ false, |
| 1231 | executor, |
| 1232 | /* reporter= */ null, |
| 1233 | /* topLevelOutputs= */ ImmutableSet.of()); |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 1236 | private RemoteSpawnRunner newSpawnRunner(Reporter reporter) { |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 1237 | return newSpawnRunner( |
| 1238 | /* verboseFailures= */ false, executor, reporter, /* topLevelOutputs= */ ImmutableSet.of()); |
ishikhman | 21c313c | 2019-09-26 07:14:09 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Jakob Buchgraber | 34784c3 | 2019-07-22 07:40:14 -0700 | [diff] [blame] | 1241 | private RemoteSpawnRunner newSpawnRunner(ImmutableSet<ActionInput> topLevelOutputs) { |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 1242 | return newSpawnRunner( |
| 1243 | /* verboseFailures= */ false, executor, /* reporter= */ null, topLevelOutputs); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | private RemoteSpawnRunner newSpawnRunner( |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 1247 | boolean verboseFailures, |
Chi Wang | 09d8f14 | 2020-10-30 01:03:16 -0700 | [diff] [blame^] | 1248 | @Nullable RemoteExecutionClient executor, |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 1249 | @Nullable Reporter reporter, |
Jakob Buchgraber | 34784c3 | 2019-07-22 07:40:14 -0700 | [diff] [blame] | 1250 | ImmutableSet<ActionInput> topLevelOutputs) { |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1251 | return new RemoteSpawnRunner( |
| 1252 | execRoot, |
| 1253 | remoteOptions, |
| 1254 | Options.getDefaults(ExecutionOptions.class), |
janakr | 61072c1 | 2020-07-07 12:28:56 -0700 | [diff] [blame] | 1255 | verboseFailures, |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1256 | reporter, |
| 1257 | "build-req-id", |
| 1258 | "command-id", |
| 1259 | cache, |
| 1260 | executor, |
Jakob Buchgraber | 20342c7 | 2019-11-12 04:56:16 -0800 | [diff] [blame] | 1261 | retryService, |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1262 | digestUtil, |
Jakob Buchgraber | 50c1004 | 2019-04-11 02:11:19 -0700 | [diff] [blame] | 1263 | logDir, |
| 1264 | topLevelOutputs); |
Jakob Buchgraber | c6c3030 | 2019-04-11 00:35:42 -0700 | [diff] [blame] | 1265 | } |
buchgr | 9f7edd7 | 2017-07-14 12:58:50 +0200 | [diff] [blame] | 1266 | } |