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.
This commit is contained in:
parent
58f9334383
commit
78a9ec15fc
2 changed files with 39 additions and 15 deletions
|
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.0"
|
||||
edition = "2015"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
foo = { git = "https://needs-proxy.invalid/git" }
|
||||
|
|
@ -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" <<EOF
|
||||
[package]
|
||||
name = "$CRATE_NAME"
|
||||
version = "$CRATE_VER"
|
||||
edition = "2015"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
foo = { git = "$REMOTE_URL" }
|
||||
EOF
|
||||
}
|
||||
|
||||
function generate_cargo_conffile() {
|
||||
mkdir ".cargo"
|
||||
cat >> .cargo/config.toml <<EOF
|
||||
|
|
@ -15,8 +43,8 @@ function test_git-fetch-with-cli() {
|
|||
local log_file
|
||||
log_file=$(mktemp)
|
||||
|
||||
rlRun "$cargo_cmd 2> $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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue