Files
gitea/modules/migration/retry_downloader_test.go
T
9cd06bf57f fix(migrations): wait out GitHub rate limits and tolerate failed patch downloads (#40012)
Large GitHub migrations failed once the API budget ran out. A rejected
request never updated the downloader's rate state, so go-github refused
every retry locally.

- Record the rate limit from error responses too, so the next request
waits for the reset
- Retry repository-wide comment pages like the other downloader calls
- Stop `waitAndPickClient` spinning when the rate refresh fails
- Skip reaction requests when the reaction rollup reports none
- Log a failed patch download instead of failing the migration

---------

Co-authored-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
2026-10-31 17:31:51 +01:00

30 lines
723 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package migration
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
type failingCommentsDownloader struct {
NullDownloader
attempts int
}
func (d *failingCommentsDownloader) GetAllComments(_ctx context.Context, _page, _perPage int) ([]*Comment, bool, error) {
d.attempts++
return nil, false, errors.New("permission denied")
}
func TestRetryDownloaderExhaustsAttempts(t *testing.T) {
source := &failingCommentsDownloader{}
_, _, err := NewRetryDownloader(source, 3, 0).GetAllComments(t.Context(), 1, 50)
assert.EqualError(t, err, "permission denied")
assert.Equal(t, 3, source.attempts)
}