diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go index 585b4d8ed8..db04f3f37b 100644 --- a/services/migrations/gitlab.go +++ b/services/migrations/gitlab.go @@ -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 diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go index f1c5423824..b0dbd81923 100644 --- a/services/migrations/gitlab_test.go +++ b/services/migrations/gitlab_test.go @@ -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()