Files
lock/redsync_test.go
zeekay 206f70cd71 refactor: one adapter — kvgo
The fork carried five client adapters: goredis (v6/v7/v8), redigo, rueidis,
valkeygo and kvgo. Only kvgo drives our client, and it is the only one any
consumer imports — hanzoai/git's globallock is the sole user and it takes kvgo.
The other four compiled four client libraries into every build to serve nobody.

Deleted with their examples, and the multi-adapter test collapsed to the case
that remains.

What keeps the old spelling, because renaming it changes behaviour rather than
branding:
  scripts.go   redis.call(...) is the server's Lua API. The SHA1 of each script
               is pinned in this file; rewriting the source changes the hash.
  tempredis    an upstream test helper — a package name, not our vocabulary. It
               is also what still pulls redigo, transitively, in tests only.
  kv/kv.go     two provenance links to the code these helpers came from.
2026-07-26 14:19:38 -07:00

91 lines
1.5 KiB
Go

package redsync
import (
"context"
"os"
"strconv"
"testing"
kvlib "github.com/hanzokv/go/v9"
"github.com/hanzokv/lock/v4/kv"
"github.com/hanzokv/lock/v4/kv/kvgo"
"github.com/stvp/tempredis"
)
var servers []*tempredis.Server
type testCase struct {
poolCount int
pools []kv.Pool
}
func makeCases(poolCount int) map[string]*testCase {
return map[string]*testCase{
"kvgo": {
poolCount,
newMockPoolsKVGo(poolCount),
},
}
}
// Maintain separate blocks of servers for each type of driver
const (
ServerPools = 6
ServerPoolSize = 8
KVGoBlock = 0
)
func TestMain(m *testing.M) {
os.Exit(testRunner(m))
}
func testRunner(m *testing.M) int {
for i := range ServerPoolSize * ServerPools {
server, err := tempredis.Start(tempredis.Config{
"port": strconv.Itoa(51200 + i),
})
if err != nil {
panic(err)
}
defer server.Term()
servers = append(servers, server)
}
return m.Run()
}
func TestRedsync(t *testing.T) {
ctx := context.Background()
for k, v := range makeCases(8) {
t.Run(k, func(t *testing.T) {
rs := New(v.pools...)
mutex := rs.NewMutex("test-redsync")
_ = mutex.Lock()
assertAcquired(ctx, t, v.pools, mutex)
})
}
}
func newMockPoolsKVGo(n int) []kv.Pool {
pools := make([]kv.Pool, n)
offset := KVGoBlock * ServerPoolSize
for i := range n {
client := kvlib.NewClient(&kvlib.Options{
Network: "unix",
Addr: servers[i+offset].Socket(),
})
pools[i] = kvgo.NewPool(client)
}
return pools
}