Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Remote: Fixes an issue when --experimental_remote_cache_async encounter flaky tests. #14241

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
Expand Down Expand Up @@ -535,13 +536,22 @@ private static Spawn createXmlGeneratingSpawn(
envBuilder.put("TEST_SHARD_INDEX", "0");
envBuilder.put("TEST_TOTAL_SHARDS", "0");
}
Map<String, String> executionInfo =
Maps.newHashMapWithExpectedSize(action.getExecutionInfo().size() + 1);
executionInfo.putAll(action.getExecutionInfo());
if (result.exitCode() != 0) {
// If the test is failed, the spawn shouldn't use remote cache since the test.xml file is
// renamed immediately after the spawn execution. If there is another test attempt, the async
// upload will fail because it cannot read the file at original position.
executionInfo.put(ExecutionRequirements.NO_REMOTE_CACHE, "");
}
return new SimpleSpawn(
action,
args,
envBuilder.build(),
// Pass the execution info of the action which is identical to the supported tags set on the
// test target. In particular, this does not set the test timeout on the spawn.
ImmutableMap.copyOf(action.getExecutionInfo()),
ImmutableMap.copyOf(executionInfo),
null,
ImmutableMap.of(),
/*inputs=*/ NestedSetBuilder.create(
Expand Down
33 changes: 33 additions & 0 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3171,4 +3171,37 @@ EOF
expect_log "-r-xr-xr-x"
}

function test_async_upload_works_for_flaky_tests() {
mkdir -p a
cat > a/BUILD <<EOF
sh_test(
name = "test",
srcs = ["test.sh"],
)

genrule(
name = "foo",
outs = ["foo.txt"],
cmd = "echo \"foo bar\" > \$@",
)
EOF
cat > a/test.sh <<EOF
#!/bin/sh
echo "it always fails"
exit 1
EOF
chmod +x a/test.sh

# Check the error message when failed to upload
bazel build --remote_cache=http://nonexistent.example.org //a:foo >& $TEST_log || fail "Failed to build"
expect_log "WARNING: Writing to Remote Cache:"

bazel test \
--remote_cache=grpc://localhost:${worker_port} \
--experimental_remote_cache_async \
--flaky_test_attempts=2 \
//a:test >& $TEST_log && fail "expected failure" || true
expect_not_log "WARNING: Writing to Remote Cache:"
}

run_suite "Remote execution and remote cache tests"