- Refactor the Go proxy for dependency injection: every proxy server, the bootstrap, the signal handler, the load balancers, and AMF0 now accept functional-option seams (factories/closures) so tests can inject fakes without binding real sockets, talking to real Redis, or racing on package globals. - Drop the package-global `lb.SrsLoadBalancer`. The bootstrap creates the LB locally and threads it through every proxy server constructor. Two old global indirections in `internal/signal` and `internal/rtmp/amf0` are likewise replaced by per-instance fields. - Rename `internal/server` → `internal/proxy` and rename the `lb` public surface for clarity: `SRSLoadBalancer` is split into `OriginService` / `HLSService` / `RTCService` and recomposed as `OriginLoadBalancer`; `SRSServer` → `OriginServer`; all proxy server types gain a `Proxy` qualifier (e.g. `RTMPServer` → `RTMPProxyServer`). - Extract the Redis client behind a new `internal/redisclient` package with a minimal `RedisClient` interface and a counterfeiter fake. - Add counterfeiter fakes (`proxyfakes`, `lbfakes`, `redisclientfakes`) and ~7.5k lines of unit tests covering bootstrap, memory + Redis LBs, all five proxy servers, the signal handler, and AMF0. - Add two new E2E flows — `proxy-e2e-srt-test.sh` (SRT publish through proxy, verify SRT/RTMP/HTTP-FLV/HLS playback) and `proxy-e2e-whip-test.sh` (WHIP publish, verify RTMP/HTTP-FLV/HLS via origin `rtc_to_rtmp`) — plus `setup-ffmpeg-with-whip.sh`, a macOS builder for an ffmpeg with openssl-DTLS WHIP and SRT support that the two scripts auto-invoke when needed. - Workspace reorg: move `memory/` and `skills/` to the repo root so all agent tools (Claude / Codex / Kiro / OpenClaw) share one source of truth via symlinks. Sync `docs/proxy/proxy-load-balancer.md` and `memory/srs-codebase-map.md` with the new names. No protocol, log, HTTP API, or wire-format changes. Refactor only — all externally observable proxy behavior is unchanged. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
328 lines
8.3 KiB
Go
328 lines
8.3 KiB
Go
// Code generated by counterfeiter. DO NOT EDIT.
|
|
package redisclientfakes
|
|
|
|
import (
|
|
"context"
|
|
"srsx/internal/redisclient"
|
|
"sync"
|
|
"time"
|
|
|
|
redis "github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
type FakeRedisClient struct {
|
|
GetStub func(context.Context, string) *redis.StringCmd
|
|
getMutex sync.RWMutex
|
|
getArgsForCall []struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
}
|
|
getReturns struct {
|
|
result1 *redis.StringCmd
|
|
}
|
|
getReturnsOnCall map[int]struct {
|
|
result1 *redis.StringCmd
|
|
}
|
|
PingStub func(context.Context) *redis.StatusCmd
|
|
pingMutex sync.RWMutex
|
|
pingArgsForCall []struct {
|
|
arg1 context.Context
|
|
}
|
|
pingReturns struct {
|
|
result1 *redis.StatusCmd
|
|
}
|
|
pingReturnsOnCall map[int]struct {
|
|
result1 *redis.StatusCmd
|
|
}
|
|
SetStub func(context.Context, string, interface{}, time.Duration) *redis.StatusCmd
|
|
setMutex sync.RWMutex
|
|
setArgsForCall []struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
arg3 interface{}
|
|
arg4 time.Duration
|
|
}
|
|
setReturns struct {
|
|
result1 *redis.StatusCmd
|
|
}
|
|
setReturnsOnCall map[int]struct {
|
|
result1 *redis.StatusCmd
|
|
}
|
|
StringStub func() string
|
|
stringMutex sync.RWMutex
|
|
stringArgsForCall []struct {
|
|
}
|
|
stringReturns struct {
|
|
result1 string
|
|
}
|
|
stringReturnsOnCall map[int]struct {
|
|
result1 string
|
|
}
|
|
invocations map[string][][]interface{}
|
|
invocationsMutex sync.RWMutex
|
|
}
|
|
|
|
func (fake *FakeRedisClient) Get(arg1 context.Context, arg2 string) *redis.StringCmd {
|
|
fake.getMutex.Lock()
|
|
ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)]
|
|
fake.getArgsForCall = append(fake.getArgsForCall, struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
}{arg1, arg2})
|
|
stub := fake.GetStub
|
|
fakeReturns := fake.getReturns
|
|
fake.recordInvocation("Get", []interface{}{arg1, arg2})
|
|
fake.getMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1, arg2)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeRedisClient) GetCallCount() int {
|
|
fake.getMutex.RLock()
|
|
defer fake.getMutex.RUnlock()
|
|
return len(fake.getArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRedisClient) GetCalls(stub func(context.Context, string) *redis.StringCmd) {
|
|
fake.getMutex.Lock()
|
|
defer fake.getMutex.Unlock()
|
|
fake.GetStub = stub
|
|
}
|
|
|
|
func (fake *FakeRedisClient) GetArgsForCall(i int) (context.Context, string) {
|
|
fake.getMutex.RLock()
|
|
defer fake.getMutex.RUnlock()
|
|
argsForCall := fake.getArgsForCall[i]
|
|
return argsForCall.arg1, argsForCall.arg2
|
|
}
|
|
|
|
func (fake *FakeRedisClient) GetReturns(result1 *redis.StringCmd) {
|
|
fake.getMutex.Lock()
|
|
defer fake.getMutex.Unlock()
|
|
fake.GetStub = nil
|
|
fake.getReturns = struct {
|
|
result1 *redis.StringCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) GetReturnsOnCall(i int, result1 *redis.StringCmd) {
|
|
fake.getMutex.Lock()
|
|
defer fake.getMutex.Unlock()
|
|
fake.GetStub = nil
|
|
if fake.getReturnsOnCall == nil {
|
|
fake.getReturnsOnCall = make(map[int]struct {
|
|
result1 *redis.StringCmd
|
|
})
|
|
}
|
|
fake.getReturnsOnCall[i] = struct {
|
|
result1 *redis.StringCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) Ping(arg1 context.Context) *redis.StatusCmd {
|
|
fake.pingMutex.Lock()
|
|
ret, specificReturn := fake.pingReturnsOnCall[len(fake.pingArgsForCall)]
|
|
fake.pingArgsForCall = append(fake.pingArgsForCall, struct {
|
|
arg1 context.Context
|
|
}{arg1})
|
|
stub := fake.PingStub
|
|
fakeReturns := fake.pingReturns
|
|
fake.recordInvocation("Ping", []interface{}{arg1})
|
|
fake.pingMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeRedisClient) PingCallCount() int {
|
|
fake.pingMutex.RLock()
|
|
defer fake.pingMutex.RUnlock()
|
|
return len(fake.pingArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRedisClient) PingCalls(stub func(context.Context) *redis.StatusCmd) {
|
|
fake.pingMutex.Lock()
|
|
defer fake.pingMutex.Unlock()
|
|
fake.PingStub = stub
|
|
}
|
|
|
|
func (fake *FakeRedisClient) PingArgsForCall(i int) context.Context {
|
|
fake.pingMutex.RLock()
|
|
defer fake.pingMutex.RUnlock()
|
|
argsForCall := fake.pingArgsForCall[i]
|
|
return argsForCall.arg1
|
|
}
|
|
|
|
func (fake *FakeRedisClient) PingReturns(result1 *redis.StatusCmd) {
|
|
fake.pingMutex.Lock()
|
|
defer fake.pingMutex.Unlock()
|
|
fake.PingStub = nil
|
|
fake.pingReturns = struct {
|
|
result1 *redis.StatusCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) PingReturnsOnCall(i int, result1 *redis.StatusCmd) {
|
|
fake.pingMutex.Lock()
|
|
defer fake.pingMutex.Unlock()
|
|
fake.PingStub = nil
|
|
if fake.pingReturnsOnCall == nil {
|
|
fake.pingReturnsOnCall = make(map[int]struct {
|
|
result1 *redis.StatusCmd
|
|
})
|
|
}
|
|
fake.pingReturnsOnCall[i] = struct {
|
|
result1 *redis.StatusCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) Set(arg1 context.Context, arg2 string, arg3 interface{}, arg4 time.Duration) *redis.StatusCmd {
|
|
fake.setMutex.Lock()
|
|
ret, specificReturn := fake.setReturnsOnCall[len(fake.setArgsForCall)]
|
|
fake.setArgsForCall = append(fake.setArgsForCall, struct {
|
|
arg1 context.Context
|
|
arg2 string
|
|
arg3 interface{}
|
|
arg4 time.Duration
|
|
}{arg1, arg2, arg3, arg4})
|
|
stub := fake.SetStub
|
|
fakeReturns := fake.setReturns
|
|
fake.recordInvocation("Set", []interface{}{arg1, arg2, arg3, arg4})
|
|
fake.setMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1, arg2, arg3, arg4)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeRedisClient) SetCallCount() int {
|
|
fake.setMutex.RLock()
|
|
defer fake.setMutex.RUnlock()
|
|
return len(fake.setArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRedisClient) SetCalls(stub func(context.Context, string, interface{}, time.Duration) *redis.StatusCmd) {
|
|
fake.setMutex.Lock()
|
|
defer fake.setMutex.Unlock()
|
|
fake.SetStub = stub
|
|
}
|
|
|
|
func (fake *FakeRedisClient) SetArgsForCall(i int) (context.Context, string, interface{}, time.Duration) {
|
|
fake.setMutex.RLock()
|
|
defer fake.setMutex.RUnlock()
|
|
argsForCall := fake.setArgsForCall[i]
|
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
|
|
}
|
|
|
|
func (fake *FakeRedisClient) SetReturns(result1 *redis.StatusCmd) {
|
|
fake.setMutex.Lock()
|
|
defer fake.setMutex.Unlock()
|
|
fake.SetStub = nil
|
|
fake.setReturns = struct {
|
|
result1 *redis.StatusCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) SetReturnsOnCall(i int, result1 *redis.StatusCmd) {
|
|
fake.setMutex.Lock()
|
|
defer fake.setMutex.Unlock()
|
|
fake.SetStub = nil
|
|
if fake.setReturnsOnCall == nil {
|
|
fake.setReturnsOnCall = make(map[int]struct {
|
|
result1 *redis.StatusCmd
|
|
})
|
|
}
|
|
fake.setReturnsOnCall[i] = struct {
|
|
result1 *redis.StatusCmd
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) String() string {
|
|
fake.stringMutex.Lock()
|
|
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
|
|
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
|
|
}{})
|
|
stub := fake.StringStub
|
|
fakeReturns := fake.stringReturns
|
|
fake.recordInvocation("String", []interface{}{})
|
|
fake.stringMutex.Unlock()
|
|
if stub != nil {
|
|
return stub()
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeRedisClient) StringCallCount() int {
|
|
fake.stringMutex.RLock()
|
|
defer fake.stringMutex.RUnlock()
|
|
return len(fake.stringArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeRedisClient) StringCalls(stub func() string) {
|
|
fake.stringMutex.Lock()
|
|
defer fake.stringMutex.Unlock()
|
|
fake.StringStub = stub
|
|
}
|
|
|
|
func (fake *FakeRedisClient) StringReturns(result1 string) {
|
|
fake.stringMutex.Lock()
|
|
defer fake.stringMutex.Unlock()
|
|
fake.StringStub = nil
|
|
fake.stringReturns = struct {
|
|
result1 string
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) StringReturnsOnCall(i int, result1 string) {
|
|
fake.stringMutex.Lock()
|
|
defer fake.stringMutex.Unlock()
|
|
fake.StringStub = nil
|
|
if fake.stringReturnsOnCall == nil {
|
|
fake.stringReturnsOnCall = make(map[int]struct {
|
|
result1 string
|
|
})
|
|
}
|
|
fake.stringReturnsOnCall[i] = struct {
|
|
result1 string
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeRedisClient) Invocations() map[string][][]interface{} {
|
|
fake.invocationsMutex.RLock()
|
|
defer fake.invocationsMutex.RUnlock()
|
|
copiedInvocations := map[string][][]interface{}{}
|
|
for key, value := range fake.invocations {
|
|
copiedInvocations[key] = value
|
|
}
|
|
return copiedInvocations
|
|
}
|
|
|
|
func (fake *FakeRedisClient) recordInvocation(key string, args []interface{}) {
|
|
fake.invocationsMutex.Lock()
|
|
defer fake.invocationsMutex.Unlock()
|
|
if fake.invocations == nil {
|
|
fake.invocations = map[string][][]interface{}{}
|
|
}
|
|
if fake.invocations[key] == nil {
|
|
fake.invocations[key] = [][]interface{}{}
|
|
}
|
|
fake.invocations[key] = append(fake.invocations[key], args)
|
|
}
|
|
|
|
var _ redisclient.RedisClient = new(FakeRedisClient)
|