fix(migrations): cancel GitLab version probes (#39023)

Bind the GitLab version probe to the migration context so a cancelled
migration does not remain blocked on a remote response.
This commit is contained in:
bircni
2026-08-22 01:54:07 +00:00
committed by GitHub
parent d2bc0097bc
commit 1f349eb1eb
2 changed files with 24 additions and 1 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, token string) (
var resp *gitlab.Response
u, _ := url.Parse(baseURL)
for len(pathParts) >= 2 {
_, resp, err = gitlabClient.Version.GetVersion()
_, resp, err = gitlabClient.Version.GetVersion(gitlab.WithContext(ctx))
if err == nil || resp != nil && resp.StatusCode == http.StatusUnauthorized {
err = nil // if no authentication given, this still should work
break
+23
View File
@@ -4,6 +4,7 @@
package migrations
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
@@ -359,6 +360,28 @@ func TestGitlabDownloadRepo(t *testing.T) {
}, rvs)
}
func TestGitlabVersionProbeUsesMigrationContext(t *testing.T) {
started := make(chan struct{})
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
close(started)
<-r.Context().Done()
}))
defer server.Close()
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
result := make(chan error, 1)
go func() {
_, err := NewGitlabDownloader(ctx, server.URL, "owner/repo", "")
result <- err
}()
<-started
cancel()
assert.Error(t, <-result)
}
func gitlabClientMockSetup(t *testing.T) (*http.ServeMux, *httptest.Server, *gitlab.Client) {
// mux is the HTTP request multiplexer used with the test server.
mux := http.NewServeMux()