modification for testability caused a panic when client tries to connect

to unknown agent.
This commit is contained in:
Erik Brakkee 2024-08-24 22:30:21 +02:00
parent a99de52e56
commit 95204a9f5b
2 changed files with 13 additions and 4 deletions

View File

@ -119,7 +119,9 @@ func (converge *MatchMaker) Connect(wsProxyMode bool,
client, err := converge.admin.AddClient(publicId, conn) client, err := converge.admin.AddClient(publicId, conn)
cleanUpFunc := func() { cleanUpFunc := func() {
converge.admin.RemoveClient(client) if client != nil {
converge.admin.RemoveClient(client)
}
converge.logStatus() converge.logStatus()
} }
defer func() { defer func() {

View File

@ -171,6 +171,14 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() {
s.checkState(1, 0) s.checkState(1, 0)
} }
func (s *MatchMakerTestSuite) Test_ConnectCLientToUnknownAgent() {
publicId := models.RendezVousId("abc")
client, err := s.connectClient(publicId)
s.NotNil(err)
s.Nil(client)
}
func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() { func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() {
agents := []string{"abc", "def", "ghi"} agents := []string{"abc", "def", "ghi"}
clients := map[string]int{"abc": 3, "def": 2, "ghi": 5} clients := map[string]int{"abc": 3, "def": 2, "ghi": 5}
@ -232,13 +240,12 @@ func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId) (*Test
return nil return nil
}) })
var err error = nil
if res[0] != nil { if res[0] != nil {
err = res[0].(error) return nil, res[0].(error)
} }
client.publicId = publicId client.publicId = publicId
client.clientId = clientId client.clientId = clientId
return client, err return client, nil
} }
func (s *MatchMakerTestSuite) checkState(nAgents int, nClients int) { func (s *MatchMakerTestSuite) checkState(nAgents int, nClients int) {