[Tests] install_nvm_from_git: stop git background gc/maintenance racing with cleanup

The test's `rm -rf "$NVM_DIR"` intermittently failed with
`rm: cannot remove...: Directory not empty`
and aborted under `set -e`.
Cause: after the clone/fetch, git can spawn a detached background gc/maintenance process that keeps writing into the clone dir while `rm -rf` runs (a concurrent writer makes the final rmdir fail).
It is not egress- or version-related
(it reproduces with all endpoints allowed),
and it is environment-timing dependent
(recently became consistent on the GitHub runners).

Disable git's background work for the test (gc.autoDetach / maintenance.auto)
so all git operations finish synchronously, and retry the rm once as a safety net.
This commit is contained in:
Jordan Harband
2026-06-03 20:12:26 -07:00
parent 61c9ff7371
commit 84079dbff3

View File

@@ -17,6 +17,9 @@ NVM_ENV=testing \. ../../install.sh
set -ex
git config --global gc.autoDetach false
git config --global maintenance.auto false
# nvm_do_install is available
type install_nvm_from_git > /dev/null 2>&1 || die 'install_nvm_from_git is not available'
@@ -94,14 +97,14 @@ test_install() {
test_step "Clones repo $message"
install_nvm_from_git
test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"
rm -rf "$NVM_DIR"
rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }
# Ensure it initializes the repository for an empty existing repository
mkdir -p "$NVM_DIR" || die 'Unable to create directory'
test_step "Initialize repo $message"
install_nvm_from_git
test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"
rm -rf "$NVM_DIR"
rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }
# Ensure it updates the repository for an existing git repository
git clone "$(nvm_source "git")" -b "v0.36.0" --depth=2 "$NVM_DIR" || die 'Unable to clone repository'
@@ -109,7 +112,7 @@ test_install() {
test_step "Updates repo $message"
install_nvm_from_git
test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"
rm -rf "$NVM_DIR"
rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }
}
# Handle latest version