fix: misc fixes in pub/gpg/tests (#38809)

- The pub registry reported the oldest version as `latest`, because the
descriptor slice is sorted ascending but the first element was used.
- Verifying a GPG or SSH key flashed success and redirected after
already writing an error response, so a failure was reported as a
success with an empty key id.
- Test packages sharing redis could tear down each other's server.
`PrepareTestRedis` started its own on the well-known port, so a package
running in parallel borrowed it and lost it when the owner's cleanup
fired. It now listens on a socket of its own.
This commit is contained in:
silverwind
2026-08-07 13:49:23 +02:00
committed by GitHub
parent dd8ef9c888
commit ec869e3052
6 changed files with 54 additions and 67 deletions
+4
View File
@@ -7,6 +7,9 @@ import (
"context"
"sync"
"testing"
"time"
"gitea.dev/modules/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -14,6 +17,7 @@ import (
func TestLockAndDo(t *testing.T) {
t.Run("redis", func(t *testing.T) {
defer test.MockVariableValue(&redisLockExpiry, 5*time.Second)() // Close waits for the extend goroutine's next tick
locker := newTestRedisLocker(t)
defaultLocker.Store(new(locker))
testLockAndDo(t)
+1 -10
View File
@@ -5,13 +5,11 @@ package globallock
import (
"context"
"os"
"sync"
"testing"
"time"
"gitea.dev/modules/test"
"gitea.dev/modules/util"
"github.com/go-redsync/redsync/v4"
"github.com/stretchr/testify/assert"
@@ -20,14 +18,7 @@ import (
func newTestRedisLocker(t *testing.T) Locker {
t.Helper()
redisURL := util.IfZero(os.Getenv("TEST_REDIS_URL"), "redis://127.0.0.1:6379/0")
rl := NewRedisLocker(redisURL).(*redisLocker)
err := rl.conn.Ping(t.Context()).Err()
if err != nil && test.AllowSkipExternalService() {
t.Skip("no redis server for testing, skipped")
}
require.NoError(t, err, "redis error for testing: %v", err)
return rl
return NewRedisLocker(test.PrepareTestRedis(t))
}
func TestLocker(t *testing.T) {