From 78a9ec15fcb8efd2fcfa066843db3c894d7299e1 Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Mon, 23 Mar 2026 11:59:53 +0100 Subject: [PATCH] net_err_suggests_fetch_with_cli: fix false positives Some test systems have catch-all DNS resolvers that point needs-proxy.invalid to loopback, resulting in a connection refused OS error instead the expected Net error. This change uses a known invalid IP to bypass any potential DNS, and also adds an extremely short timeout to enforce a Net error. Also make the test pattern matching a bit more fuzzy to avoid future false positives. Remove the standalone Cargo.toml file and integrate it into the main script to be able to parametrize it. --- .../Cargo.toml | 8 ---- .../runtest.sh | 46 ++++++++++++++++--- 2 files changed, 39 insertions(+), 15 deletions(-) delete mode 100644 tests/Sanity/net_err_suggests_fetch_with_cli/Cargo.toml diff --git a/tests/Sanity/net_err_suggests_fetch_with_cli/Cargo.toml b/tests/Sanity/net_err_suggests_fetch_with_cli/Cargo.toml deleted file mode 100644 index 24ea143..0000000 --- a/tests/Sanity/net_err_suggests_fetch_with_cli/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "foo" -version = "0.0.0" -edition = "2015" -authors = [] - -[dependencies] -foo = { git = "https://needs-proxy.invalid/git" } diff --git a/tests/Sanity/net_err_suggests_fetch_with_cli/runtest.sh b/tests/Sanity/net_err_suggests_fetch_with_cli/runtest.sh index 2094ae0..4acce0a 100755 --- a/tests/Sanity/net_err_suggests_fetch_with_cli/runtest.sh +++ b/tests/Sanity/net_err_suggests_fetch_with_cli/runtest.sh @@ -2,6 +2,34 @@ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k . /usr/share/beakerlib/beakerlib.sh || exit 1 +# For the test remote depenency, we use a TEST-NET-1 address (192.0.2.1) instead +# "needs-proxy.invalid" like upstream, to deal with potential catch-all DNS +# resolvers that redirect any invalid domain to loopback. These result in a +# connection refused (OS error) for any invalid host, but we need a network +# error for cargo to recommend using fetch-with-cli.SS +# To achieve it we use a documented test IP with a very short timeout that +# will simulate the same effect of unreachable host, causing cargo to suggest +# using the git fetch option. + +CRATE_NAME="foo" +CRATE_VER="0.0.0" +REMOTE_URL="https://192.0.2.1/git" + + +function generate_cargo_toml() { + local dest_dir=$1 + cat >> "$dest_dir/Cargo.toml" <> .cargo/config.toml < $log_file" 101 - rlAssertGrep 'Unable to update https://needs-proxy.invalid/git' "$log_file" || cat "$log_file" + rlRun "$cargo_cmd |& tee $log_file" 101 + rlAssertGrep "Unable to update $REMOTE_URL" "$log_file" || cat "$log_file" rlAssertNotGrep "net.git-fetch-with-cli" "$log_file" || cat "$log_file" rm -f "$log_file" @@ -26,18 +54,22 @@ rlJournalStart rlPhaseStartSetup declare tmp rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" - rlRun "cp Cargo.toml $tmp" + # rlRun "cp Cargo.toml $tmp" + rlRun "generate_cargo_toml $tmp" rlRun "pushd $tmp" rlRun "mkdir src && touch src/lib.rs" rlRun "set -o pipefail" - + # Cargo will try to resolve an IP that will never reply back. + # To make the test run faster, reduce the timeout to 1 second instead + # the default 30s + rlRun "export HTTP_TIMEOUT=1" rlPhaseEnd rlPhaseStartTest - rlRun "cargo check -v 2> output.log" 101 + rlRun "cargo check -v |& tee output.log" 101 # Ensure DNS was not able to resolve the remote - rlAssertGrep 'spurious network error \([0-9]+ .* remaining\): .*resolve .*needs-proxy\.invalid: .*known' output.log -E - rlAssertGrep 'Unable to update https://needs-proxy.invalid/git' output.log + rlAssertGrep 'spurious network error' output.log + rlAssertGrep "Unable to update $REMOTE_URL" output.log # Ensure cargo suggests using net.git-fetch-with-cli rlAssertGrep "net.git-fetch-with-cli" output.log