MCPcopy
hub / github.com/helm/helm / TestParallelDownloadTo

Function TestParallelDownloadTo

pkg/downloader/chart_downloader_windows_test.go:34–131  ·  view source on GitHub ↗

TestParallelDownloadTo tests that parallel downloads to the same file don't cause "Access Denied" errors on Windows. This test is Windows-specific because the file locking behavior is only needed on Windows.

(t *testing.T)

Source from the content-addressed store, hash-verified

32// don't cause "Access Denied" errors on Windows. This test is Windows-specific
33// because the file locking behavior is only needed on Windows.
34func TestParallelDownloadTo(t *testing.T) {
35 // Set up a simple test server with a chart
36 srv := repotest.NewTempServer(t, repotest.WithChartSourceGlob("testdata/*.tgz"))
37 defer srv.Stop()
38
39 if err := srv.CreateIndex(); err != nil {
40 t.Fatal(err)
41 }
42
43 dest := t.TempDir()
44 cacheDir := t.TempDir()
45
46 c := ChartDownloader{
47 Out: os.Stderr,
48 RepositoryConfig: repoConfig,
49 RepositoryCache: repoCache,
50 ContentCache: cacheDir,
51 Cache: &DiskCache{Root: cacheDir},
52 Getters: getter.All(&cli.EnvSettings{
53 RepositoryConfig: repoConfig,
54 RepositoryCache: repoCache,
55 ContentCache: cacheDir,
56 }),
57 }
58
59 // Use a direct URL to bypass repository lookup
60 chartURL := srv.URL() + "/local-subchart-0.1.0.tgz"
61
62 // Number of parallel downloads to attempt
63 numDownloads := 10
64 var wg sync.WaitGroup
65 errors := make([]error, numDownloads)
66
67 // Launch multiple goroutines to download the same chart simultaneously
68 for i := 0; i < numDownloads; i++ {
69 wg.Add(1)
70 go func(index int) {
71 defer wg.Done()
72 _, _, err := c.DownloadTo(chartURL, "", dest)
73 errors[index] = err
74 }(i)
75 }
76
77 wg.Wait()
78
79 // Check if any download failed
80 failedCount := 0
81 for i, err := range errors {
82 if err != nil {
83 t.Logf("Download %d failed: %v", i, err)
84 failedCount++
85 }
86 }
87
88 // With the file locking fix, all parallel downloads should succeed
89 if failedCount > 0 {
90 t.Errorf("Parallel downloads failed: %d out of %d downloads failed due to concurrent file access", failedCount, numDownloads)
91 }

Callers

nothing calls this directly

Calls 12

DownloadToMethod · 0.95
NewTempServerFunction · 0.92
WithChartSourceGlobFunction · 0.92
AllFunction · 0.92
StopMethod · 0.80
CreateIndexMethod · 0.80
FatalMethod · 0.80
URLMethod · 0.80
CloseMethod · 0.80
WaitMethod · 0.65
AddMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…