test: add integration test for issue #2502 race condition with shared local chart

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2026-04-18 08:48:34 +08:00
parent 5155ea5687
commit 6fc16f4ed2
5 changed files with 89 additions and 0 deletions

View File

@ -96,6 +96,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
# TEST CASES----------------------------------------------------------------------------------------------------------
. ${dir}/test-cases/issue-2502-race-condition-local-chart.sh
. ${dir}/test-cases/chart-deps-condition.sh
. ${dir}/test-cases/fetch-forl-local-chart.sh
. ${dir}/test-cases/suppress-output-line-regex.sh

View File

@ -0,0 +1,57 @@
# Integration test for issue #2502: Race condition when multiple releases share a local chart
# https://github.com/helmfile/helmfile/issues/2502
#
# When multiple releases reference the same local chart, concurrent goroutines
# race on rewriting Chart.yaml dependencies, causing:
# "Error: validation: chart.metadata.name is required"
#
# This test verifies the fix works WITHOUT --concurrency 1 workaround.
issue_2502_input_dir="${cases_dir}/issue-2502-race-condition-local-chart/input"
issue_2502_tmp=$(mktemp -d)
actual="${issue_2502_tmp}/actual.yaml"
cleanup_issue_2502() {
if [ -n "${issue_2502_tmp}" ] && [ -d "${issue_2502_tmp}" ]; then
rm -rf "${issue_2502_tmp}"
fi
}
trap cleanup_issue_2502 EXIT
test_start "issue #2502: race condition with shared local chart"
info "Running helmfile template with 5 releases sharing the same local chart (default concurrency)"
# Run WITHOUT --concurrency 1 to test the fix.
# Before the fix, this would intermittently fail with:
# "Error: validation: chart.metadata.name is required"
# Run multiple iterations to increase chance of catching a race.
pass=0
iterations=5
for i in $(seq 1 ${iterations}); do
if ${helmfile} -f ${issue_2502_input_dir}/helmfile.yaml -e test template --skip-deps > ${actual} 2>&1; then
pass=$((pass + 1))
else
cat ${actual}
fail "helmfile template failed on iteration ${i}/${iterations} (race condition on shared local chart)"
fi
done
if [ ${pass} -ne ${iterations} ]; then
fail "Expected ${iterations}/${iterations} passes but got ${pass}/${iterations}"
fi
info "All ${iterations} iterations passed successfully"
# Verify all 5 releases are present in output
for name in app app-2 app-3 app-4 app-5; do
if ! grep -q "name: ${name}" ${actual}; then
fail "Output should contain release '${name}'"
fi
done
cleanup_issue_2502
trap - EXIT
test_pass "issue #2502: race condition with shared local chart"

View File

@ -0,0 +1,10 @@
dependencies:
- name: raw
repository: file://../../../charts/raw
version: 0.0.1
apiVersion: v2
appVersion: "1.0.0"
description: A test chart for race condition reproduction
name: my-chart
type: application
version: 0.1.0

View File

@ -0,0 +1,8 @@
templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
key: value

View File

@ -0,0 +1,13 @@
environments:
test: {}
releases:
- name: app
chart: helm/my-chart
- name: app-2
chart: helm/my-chart
- name: app-3
chart: helm/my-chart
- name: app-4
chart: helm/my-chart
- name: app-5
chart: helm/my-chart