wsproxy mode tested.
This commit is contained in:
parent
0801310542
commit
e31ab7176b
@ -11,6 +11,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -111,6 +113,10 @@ type TestClient struct {
|
|||||||
serverSIdeConn iowrappers.ReadWriteAddrCloser
|
serverSIdeConn iowrappers.ReadWriteAddrCloser
|
||||||
publicId models.RendezVousId
|
publicId models.RendezVousId
|
||||||
clientId models.ClientId
|
clientId models.ClientId
|
||||||
|
|
||||||
|
// for wsproxy mode
|
||||||
|
serverProtocol comms.ProtocolVersion
|
||||||
|
clientConnectionInfo comms.ClientConnectionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestClient(ctx context.Context) *TestClient {
|
func NewTestClient(ctx context.Context) *TestClient {
|
||||||
@ -127,6 +133,26 @@ func (c *TestClient) Disconnect() {
|
|||||||
c.clientSideConn.Close()
|
c.clientSideConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *TestClient) WsproxyInit() error {
|
||||||
|
channel := comms.NewGOBChannel(c.clientSideConn)
|
||||||
|
serverProtocol, err := comms.ReceiveWithTimeout[comms.ProtocolVersion](channel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.serverProtocol = serverProtocol
|
||||||
|
|
||||||
|
clientConnectionInfo, err := comms.ReceiveWithTimeout[comms.ClientConnectionInfo](channel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.clientConnectionInfo = clientConnectionInfo
|
||||||
|
err = comms.SendWithTimeout(channel, comms.NewEnvironmentInfo(os.Getenv("SHELL")))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MatchMakerTestSuite) Test_newMatchMaker() {
|
func (s *MatchMakerTestSuite) Test_newMatchMaker() {
|
||||||
s.checkState(0, 0)
|
s.checkState(0, 0)
|
||||||
}
|
}
|
||||||
@ -152,7 +178,7 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() {
|
|||||||
waitForAgentFunc := s.registerAgent(publicId, agent)
|
waitForAgentFunc := s.registerAgent(publicId, agent)
|
||||||
go waitForAgentFunc()
|
go waitForAgentFunc()
|
||||||
|
|
||||||
client, err := s.connectClient(publicId)
|
client, err := s.connectClient(publicId, false)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
|
|
||||||
s.checkState(1, 1)
|
s.checkState(1, 1)
|
||||||
@ -174,9 +200,8 @@ func (s *MatchMakerTestSuite) Test_singleAgentAndClient() {
|
|||||||
func (s *MatchMakerTestSuite) Test_ConnectCLientToUnknownAgent() {
|
func (s *MatchMakerTestSuite) Test_ConnectCLientToUnknownAgent() {
|
||||||
publicId := models.RendezVousId("abc")
|
publicId := models.RendezVousId("abc")
|
||||||
|
|
||||||
client, err := s.connectClient(publicId)
|
_, err := s.connectClient(publicId, false)
|
||||||
s.NotNil(err)
|
s.NotNil(err)
|
||||||
s.Nil(client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() {
|
func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() {
|
||||||
@ -194,7 +219,7 @@ func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() {
|
|||||||
testClients := make([]*TestClient, 0)
|
testClients := make([]*TestClient, 0)
|
||||||
for publicId, nclients := range clients {
|
for publicId, nclients := range clients {
|
||||||
for range nclients {
|
for range nclients {
|
||||||
client, err := s.connectClient(models.RendezVousId(publicId))
|
client, err := s.connectClient(models.RendezVousId(publicId), false)
|
||||||
s.Require().Nil(err)
|
s.Require().Nil(err)
|
||||||
testClients = append(testClients, client)
|
testClients = append(testClients, client)
|
||||||
}
|
}
|
||||||
@ -220,14 +245,14 @@ func (s *MatchMakerTestSuite) Test_multipleAgentsAndClients() {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId) (*TestClient, error) {
|
func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId, wsproxyMode bool) (*TestClient, error) {
|
||||||
client := NewTestClient(s.ctx)
|
client := NewTestClient(s.ctx)
|
||||||
var clientId models.ClientId
|
var clientId models.ClientId
|
||||||
res := testsupport.RunAndWait(
|
res := testsupport.RunAndWait(
|
||||||
&s.Suite,
|
&s.Suite,
|
||||||
func() any {
|
func() any {
|
||||||
//server
|
//server
|
||||||
clientIdCreated, synchronizer, err := s.matchMaker.Connect(false, publicId, client.serverSIdeConn)
|
clientIdCreated, synchronizer, err := s.matchMaker.Connect(wsproxyMode, publicId, client.serverSIdeConn)
|
||||||
clientId = clientIdCreated
|
clientId = clientIdCreated
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Println("test: synchronizing streams.")
|
log.Println("test: synchronizing streams.")
|
||||||
@ -236,12 +261,14 @@ func (s *MatchMakerTestSuite) connectClient(publicId models.RendezVousId) (*Test
|
|||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
func() any {
|
func() any {
|
||||||
// client, nothing to do with wsproxy mode off.
|
if wsproxyMode {
|
||||||
|
client.WsproxyInit()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
if res[0] != nil {
|
if res[0] != nil {
|
||||||
return nil, res[0].(error)
|
return client, res[0].(error)
|
||||||
}
|
}
|
||||||
client.publicId = publicId
|
client.publicId = publicId
|
||||||
client.clientId = clientId
|
client.clientId = clientId
|
||||||
@ -287,3 +314,40 @@ func (s *MatchMakerTestSuite) registerAgent(publicId models.RendezVousId, agent
|
|||||||
}
|
}
|
||||||
return res[0].(WaitForAgentFunc)
|
return res[0].(WaitForAgentFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MatchMakerTestSuite) Test_ConnectWsproxyMode() {
|
||||||
|
publicId := models.RendezVousId("abc")
|
||||||
|
agent := NewTestAgent(s.ctx)
|
||||||
|
|
||||||
|
waitForAgentFunc := s.registerAgent(publicId, agent)
|
||||||
|
go waitForAgentFunc()
|
||||||
|
|
||||||
|
client, err := s.connectClient(publicId, true)
|
||||||
|
s.Nil(err)
|
||||||
|
|
||||||
|
s.checkState(1, 1)
|
||||||
|
|
||||||
|
agentClientSideConn, err := agent.listener.GetConnection(string(client.clientId))
|
||||||
|
log.Printf("Agent side conn %v", agentClientSideConn)
|
||||||
|
s.Nil(err)
|
||||||
|
testsupport.BidirectionalConnectionCheck(
|
||||||
|
&s.Suite, "testmsg",
|
||||||
|
client.clientSideConn,
|
||||||
|
agentClientSideConn)
|
||||||
|
|
||||||
|
s.True(client.clientConnectionInfo.Ok)
|
||||||
|
|
||||||
|
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) Test_ConnectWsproxyModeAgentNotFound() {
|
||||||
|
publicId := models.RendezVousId("abc")
|
||||||
|
|
||||||
|
client, err := s.connectClient(publicId, true)
|
||||||
|
s.NotNil(err)
|
||||||
|
s.True(strings.Contains(err.Error(), "No agent found for rendez-vous id"))
|
||||||
|
s.False(client.clientConnectionInfo.Ok)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user