Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
//go:build unit
|
||||
|
||||
package xai
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alicebob/miniredis/v2"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSessionStoreRedisFallbackIsLimitedToFailedWrites(t *testing.T) {
|
||||
mr := miniredis.RunT(t)
|
||||
client := redis.NewClient(&redis.Options{Addr: mr.Addr(), MaxRetries: -1})
|
||||
t.Cleanup(func() { _ = client.Close() })
|
||||
store := NewRedisSessionStore(client)
|
||||
defer store.Stop()
|
||||
session := func(state string) *OAuthSession { return &OAuthSession{State: state, CreatedAt: time.Now()} }
|
||||
|
||||
store.Set("remote", session("remote"))
|
||||
require.NoError(t, store.remote.Delete(context.Background(), "remote"))
|
||||
_, ok := store.Get("remote")
|
||||
require.False(t, ok, "a remote miss must not revive the stale local copy")
|
||||
|
||||
mr.Close()
|
||||
store.Set("local-only", session("local"))
|
||||
got, ok := store.Get("local-only")
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "local", got.State)
|
||||
require.True(t, store.TryConsumeSession("local-only"))
|
||||
require.False(t, store.TryConsumeSession("local-only"))
|
||||
}
|
||||
Reference in New Issue
Block a user