Skip to content

Commit

Permalink
Fix order-dependent test in ActionCacheCheckerTest.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 578209267
Change-Id: I87dc1c4bed973e68c5aa8e4bee26e5b4b313062a
  • Loading branch information
coeuvre authored and copybara-github committed Oct 31, 2023
1 parent ddbb003 commit 5d63b52
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ARTIFACT_OWNER;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.createArtifact;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.createTreeArtifactWithGeneratingAction;
import static com.google.devtools.build.lib.vfs.FileSystemUtils.readContent;
import static com.google.devtools.build.lib.vfs.FileSystemUtils.writeIsoLatin1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -398,9 +399,10 @@ public void testDifferentRemoteDefaultPlatform() throws Exception {
@Test
public void testDifferentFiles() throws Exception {
Action action = new WriteEmptyOutputAction();
runAction(action); // Not cached.
runAction(action); // Not cached.
assertThat(readContent(action.getPrimaryOutput().getPath(), UTF_8)).isEmpty();
writeContentAsLatin1(action.getPrimaryOutput().getPath(), "modified");
runAction(action); // Cache miss because output files were modified.
runAction(action); // Cache miss because output files were modified.

assertStatistics(
0,
Expand Down Expand Up @@ -462,12 +464,18 @@ public synchronized NestedSet<Artifact> getInputs() {
Order.STABLE_ORDER, ActionsTestUtil.createArtifact(root, path));
}
};
runAction(action); // Not cached so recorded as different deps.
// Manually register outputs of middleman action in `filesToDelete` because it won't get a cache
// token to execute and register in `runAction`. Failing to delete outputs may populate the
// filesystem for other test cases. b/308017721
for (var output : action.getOutputs()) {
filesToDelete.add(output.getPath());
}
runAction(action); // Not cached so recorded as different deps.
writeContentAsLatin1(action.getPrimaryInput().getPath(), "modified");
runAction(action); // Cache miss because input files were modified.
runAction(action); // Cache miss because input files were modified.
writeContentAsLatin1(action.getPrimaryOutput().getPath(), "modified");
runAction(action); // Outputs are not considered for middleman actions, so this is a cache hit.
runAction(action); // Outputs are not considered for middleman actions, so this is a cache hit.
runAction(action); // Outputs are not considered for middleman actions, so this is a cache hit.
runAction(action); // Outputs are not considered for middleman actions, so this is a cache hit.

assertStatistics(
2,
Expand Down Expand Up @@ -1688,7 +1696,7 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext) {
Path path = output.getPath();
if (!path.exists()) {
try {
FileSystemUtils.writeContentAsLatin1(path, "");
writeContentAsLatin1(path, "");
} catch (IOException e) {
throw new IllegalStateException("Failed to create output", e);
}
Expand Down

0 comments on commit 5d63b52

Please sign in to comment.