Small refactor (#148)

* small refactor

* extra line

* fix room allocator test

* selector fakes not used

* keep decisions out of router

* put nodeId logic back

* fix room allocator test
This commit is contained in:
David Colburn
2021-10-18 21:49:16 -05:00
committed by GitHub
parent 1d626ba053
commit 0c8fe361b2
23 changed files with 344 additions and 381 deletions
@@ -1,124 +0,0 @@
// Code generated by counterfeiter. DO NOT EDIT.
package routingfakes
import (
"sync"
"github.com/livekit/livekit-server/pkg/routing"
livekit "github.com/livekit/protocol/proto"
)
type FakeNodeSelector struct {
SelectNodeStub func([]*livekit.Node, *livekit.Room) (*livekit.Node, error)
selectNodeMutex sync.RWMutex
selectNodeArgsForCall []struct {
arg1 []*livekit.Node
arg2 *livekit.Room
}
selectNodeReturns struct {
result1 *livekit.Node
result2 error
}
selectNodeReturnsOnCall map[int]struct {
result1 *livekit.Node
result2 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *FakeNodeSelector) SelectNode(arg1 []*livekit.Node, arg2 *livekit.Room) (*livekit.Node, error) {
var arg1Copy []*livekit.Node
if arg1 != nil {
arg1Copy = make([]*livekit.Node, len(arg1))
copy(arg1Copy, arg1)
}
fake.selectNodeMutex.Lock()
ret, specificReturn := fake.selectNodeReturnsOnCall[len(fake.selectNodeArgsForCall)]
fake.selectNodeArgsForCall = append(fake.selectNodeArgsForCall, struct {
arg1 []*livekit.Node
arg2 *livekit.Room
}{arg1Copy, arg2})
stub := fake.SelectNodeStub
fakeReturns := fake.selectNodeReturns
fake.recordInvocation("SelectNode", []interface{}{arg1Copy, arg2})
fake.selectNodeMutex.Unlock()
if stub != nil {
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1, ret.result2
}
return fakeReturns.result1, fakeReturns.result2
}
func (fake *FakeNodeSelector) SelectNodeCallCount() int {
fake.selectNodeMutex.RLock()
defer fake.selectNodeMutex.RUnlock()
return len(fake.selectNodeArgsForCall)
}
func (fake *FakeNodeSelector) SelectNodeCalls(stub func([]*livekit.Node, *livekit.Room) (*livekit.Node, error)) {
fake.selectNodeMutex.Lock()
defer fake.selectNodeMutex.Unlock()
fake.SelectNodeStub = stub
}
func (fake *FakeNodeSelector) SelectNodeArgsForCall(i int) ([]*livekit.Node, *livekit.Room) {
fake.selectNodeMutex.RLock()
defer fake.selectNodeMutex.RUnlock()
argsForCall := fake.selectNodeArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *FakeNodeSelector) SelectNodeReturns(result1 *livekit.Node, result2 error) {
fake.selectNodeMutex.Lock()
defer fake.selectNodeMutex.Unlock()
fake.SelectNodeStub = nil
fake.selectNodeReturns = struct {
result1 *livekit.Node
result2 error
}{result1, result2}
}
func (fake *FakeNodeSelector) SelectNodeReturnsOnCall(i int, result1 *livekit.Node, result2 error) {
fake.selectNodeMutex.Lock()
defer fake.selectNodeMutex.Unlock()
fake.SelectNodeStub = nil
if fake.selectNodeReturnsOnCall == nil {
fake.selectNodeReturnsOnCall = make(map[int]struct {
result1 *livekit.Node
result2 error
})
}
fake.selectNodeReturnsOnCall[i] = struct {
result1 *livekit.Node
result2 error
}{result1, result2}
}
func (fake *FakeNodeSelector) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.selectNodeMutex.RLock()
defer fake.selectNodeMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *FakeNodeSelector) 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 _ routing.NodeSelector = new(FakeNodeSelector)
+30 -30
View File
@@ -22,6 +22,10 @@ type FakeRouter struct {
clearRoomStateReturnsOnCall map[int]struct {
result1 error
}
DrainStub func()
drainMutex sync.RWMutex
drainArgsForCall []struct {
}
GetNodeStub func(string) (*livekit.Node, error)
getNodeMutex sync.RWMutex
getNodeArgsForCall []struct {
@@ -71,10 +75,6 @@ type FakeRouter struct {
onRTCMessageArgsForCall []struct {
arg1 routing.RTCMessageCallback
}
PreStopStub func()
preStopMutex sync.RWMutex
preStopArgsForCall []struct {
}
RegisterNodeStub func() error
registerNodeMutex sync.RWMutex
registerNodeArgsForCall []struct {
@@ -231,6 +231,30 @@ func (fake *FakeRouter) ClearRoomStateReturnsOnCall(i int, result1 error) {
}{result1}
}
func (fake *FakeRouter) Drain() {
fake.drainMutex.Lock()
fake.drainArgsForCall = append(fake.drainArgsForCall, struct {
}{})
stub := fake.DrainStub
fake.recordInvocation("Drain", []interface{}{})
fake.drainMutex.Unlock()
if stub != nil {
fake.DrainStub()
}
}
func (fake *FakeRouter) DrainCallCount() int {
fake.drainMutex.RLock()
defer fake.drainMutex.RUnlock()
return len(fake.drainArgsForCall)
}
func (fake *FakeRouter) DrainCalls(stub func()) {
fake.drainMutex.Lock()
defer fake.drainMutex.Unlock()
fake.DrainStub = stub
}
func (fake *FakeRouter) GetNode(arg1 string) (*livekit.Node, error) {
fake.getNodeMutex.Lock()
ret, specificReturn := fake.getNodeReturnsOnCall[len(fake.getNodeArgsForCall)]
@@ -480,30 +504,6 @@ func (fake *FakeRouter) OnRTCMessageArgsForCall(i int) routing.RTCMessageCallbac
return argsForCall.arg1
}
func (fake *FakeRouter) PreStop() {
fake.preStopMutex.Lock()
fake.preStopArgsForCall = append(fake.preStopArgsForCall, struct {
}{})
stub := fake.PreStopStub
fake.recordInvocation("PreStop", []interface{}{})
fake.preStopMutex.Unlock()
if stub != nil {
fake.PreStopStub()
}
}
func (fake *FakeRouter) PreStopCallCount() int {
fake.preStopMutex.RLock()
defer fake.preStopMutex.RUnlock()
return len(fake.preStopArgsForCall)
}
func (fake *FakeRouter) PreStopCalls(stub func()) {
fake.preStopMutex.Lock()
defer fake.preStopMutex.Unlock()
fake.PreStopStub = stub
}
func (fake *FakeRouter) RegisterNode() error {
fake.registerNodeMutex.Lock()
ret, specificReturn := fake.registerNodeReturnsOnCall[len(fake.registerNodeArgsForCall)]
@@ -944,6 +944,8 @@ func (fake *FakeRouter) Invocations() map[string][][]interface{} {
defer fake.invocationsMutex.RUnlock()
fake.clearRoomStateMutex.RLock()
defer fake.clearRoomStateMutex.RUnlock()
fake.drainMutex.RLock()
defer fake.drainMutex.RUnlock()
fake.getNodeMutex.RLock()
defer fake.getNodeMutex.RUnlock()
fake.getNodeForRoomMutex.RLock()
@@ -954,8 +956,6 @@ func (fake *FakeRouter) Invocations() map[string][][]interface{} {
defer fake.onNewParticipantRTCMutex.RUnlock()
fake.onRTCMessageMutex.RLock()
defer fake.onRTCMessageMutex.RUnlock()
fake.preStopMutex.RLock()
defer fake.preStopMutex.RUnlock()
fake.registerNodeMutex.RLock()
defer fake.registerNodeMutex.RUnlock()
fake.removeDeadNodesMutex.RLock()