From d21f9c847f8ba2a5015de7f3baf3fbe5803c0593 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 24 Aug 2024 19:57:02 +0200 Subject: [PATCH] connectClient() extracted to make it easy to connect a client. --- pkg/server/matchmaker/matchmaker_test.go | 35 ++++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pkg/server/matchmaker/matchmaker_test.go b/pkg/server/matchmaker/matchmaker_test.go index 80275c6..1e4d599 100644 --- a/pkg/server/matchmaker/matchmaker_test.go +++ b/pkg/server/matchmaker/matchmaker_test.go @@ -149,6 +149,25 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() { waitForAgentFunc := s.registerAgent(publicId, agent) go waitForAgentFunc() + client, clientId := s.connectClient(publicId) + + s.checkState(1, 1) + + agentClientSideConn, err := agent.listener.GetConnection(string(clientId)) + log.Printf("Agent side conn %v", agentClientSideConn) + s.Nil(err) + testsupport.BidirectionalConnectionCheck( + &s.Suite, "testmsg", + client.clientSideConn, + agentClientSideConn) + + client.Disconnect() + // It is the agents choice to exit> The test agent does not exit by default when + // there are no more connections. + s.checkState(1, 0) +} + +func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId) (*TestClient, models.ClientId) { client := NewTestClient(s.ctx) var clientId models.ClientId testsupport.RunAndWait( @@ -168,21 +187,7 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() { // client, nothing to do with wsproxy mode off. return nil }) - - s.checkState(1, 1) - - agentClientSideConn, err := agent.listener.GetConnection(string(clientId)) - log.Printf("Agent side conn %v", agentClientSideConn) - s.Nil(err) - testsupport.BidirectionalConnectionCheck( - &s.Suite, "testmsg", - client.clientSideConn, - agentClientSideConn) - - client.Disconnect() - // It is the agents choice to exit> The test agent does not exit by default when - // there are no more connections. - s.checkState(1, 0) + return client, clientId } func (s *MatchMakerTestSuite) checkState(nAgents int, nClients int) {