mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-23 14:10:40 +00:00
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:
@@ -105,7 +105,7 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, token string) (
|
|||||||
var resp *gitlab.Response
|
var resp *gitlab.Response
|
||||||
u, _ := url.Parse(baseURL)
|
u, _ := url.Parse(baseURL)
|
||||||
for len(pathParts) >= 2 {
|
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 {
|
if err == nil || resp != nil && resp.StatusCode == http.StatusUnauthorized {
|
||||||
err = nil // if no authentication given, this still should work
|
err = nil // if no authentication given, this still should work
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -359,6 +360,28 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
|||||||
}, rvs)
|
}, 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) {
|
func gitlabClientMockSetup(t *testing.T) (*http.ServeMux, *httptest.Server, *gitlab.Client) {
|
||||||
// mux is the HTTP request multiplexer used with the test server.
|
// mux is the HTTP request multiplexer used with the test server.
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|||||||
Reference in New Issue
Block a user