Skip to content

Commit

Permalink
Attempt to deflake workspace_resolved_test
Browse files Browse the repository at this point in the history
I wasn't able to run this test locally, so haven't been able to figure out the exact source of the flakiness. But my theory is that it's flaky because `date +%s` returns seconds since epoch, and the two Bazel invocations might sometimes be so fast that they happen within the same second, cause the flake. So I changed this test to be "definitely nonreproducible" by making it copy a file from outside the repo, which I change between the invocations.

Fixes bazelbuild#19323

PiperOrigin-RevId: 563351011
Change-Id: I86a8fda441d129306038c15ee99fa63b764b7d4a
  • Loading branch information
Wyverald authored and copybara-github committed Sep 7, 2023
1 parent f83cc93 commit 693ffa6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/test/shell/bazel/workspace_resolved_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -796,27 +796,29 @@ test_non_reproducibility_detected() {
mkdir repo
cd repo
touch BUILD
cat > rule.bzl <<'EOF'
def _time_rule_impl(ctx):
ctx.execute(["bash", "-c", "date +%s > timestamp"])
cat > rule.bzl <<EOF
def _lol_rule_impl(ctx):
ctx.execute(["bash", "-c", "cp ${EXTREPODIR}/lol ."])
time_rule = repository_rule(
implementation = _time_rule_impl,
lol_rule = repository_rule(
implementation = _lol_rule_impl,
attrs = {},
)
EOF
cat > WORKSPACE <<'EOF'
load("//:rule.bzl", "time_rule")
cat > WORKSPACE <<EOF
load("//:rule.bzl", "lol_rule")
time_rule(name="timestamprepo")
lol_rule(name="lolrule")
EOF

echo foo > ../lol
bazel sync --experimental_repository_resolved_file=resolved.bzl
cat resolved.bzl > /dev/null || fail "resolved.bzl should exist"
echo bar > ../lol
bazel sync --experimental_repository_hash_file=`pwd`/resolved.bzl \
--experimental_verify_repository_rules='//:rule.bzl%time_rule' \
--experimental_verify_repository_rules='//:rule.bzl%lol_rule' \
> "${TEST_log}" 2>&1 && fail "expected failure" || :
expect_log "timestamprepo.*hash"
expect_log "lolrule.*hash"
}

test_chain_resolved() {
Expand Down

0 comments on commit 693ffa6

Please sign in to comment.