prepare test for more agents and clietns.
This commit is contained in:
parent
eb6da5da99
commit
2c2aeff8f5
@ -37,13 +37,15 @@ type AdminTestSuite struct {
|
|||||||
cancelFunc context.CancelFunc
|
cancelFunc context.CancelFunc
|
||||||
pprofServer *http.Server
|
pprofServer *http.Server
|
||||||
|
|
||||||
agentReadWriter io.ReadWriteCloser
|
|
||||||
serverReadWriter io.ReadWriteCloser
|
|
||||||
|
|
||||||
admin *Admin
|
admin *Admin
|
||||||
hostKey []byte
|
hostKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AdminTestSuite) createPipe() (io.ReadWriteCloser, io.ReadWriteCloser) {
|
||||||
|
bitpipe := testsupport.NewInmemoryConnection(s.ctx, "inmemory", 10)
|
||||||
|
return bitpipe.Front(), bitpipe.Back()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *AdminTestSuite) SetupSuite() {
|
func (s *AdminTestSuite) SetupSuite() {
|
||||||
s.pprofServer = testsupport.StartPprof("")
|
s.pprofServer = testsupport.StartPprof("")
|
||||||
}
|
}
|
||||||
@ -57,16 +59,6 @@ func (s *AdminTestSuite) SetupTest() {
|
|||||||
s.ctx = ctx
|
s.ctx = ctx
|
||||||
s.cancelFunc = cancelFunc
|
s.cancelFunc = cancelFunc
|
||||||
|
|
||||||
// Could have also used net.Pipe but net.Pipe uses synchronous communication
|
|
||||||
// by default and the bitpipe implementation can become asynchronous when
|
|
||||||
// a channels ize > 0 is passed in. Also the test utility respects the context
|
|
||||||
// so also deals with cancellation much better than net.Pipe.
|
|
||||||
bitpipe := testsupport.NewInmemoryConnection(s.ctx, "inmemory", 10)
|
|
||||||
agentReadWriter := bitpipe.Front()
|
|
||||||
serverReadWriter := bitpipe.Back()
|
|
||||||
s.agentReadWriter = agentReadWriter
|
|
||||||
s.serverReadWriter = serverReadWriter
|
|
||||||
|
|
||||||
s.admin = NewAdmin()
|
s.admin = NewAdmin()
|
||||||
s.hostKey = make([]byte, 100)
|
s.hostKey = make([]byte, 100)
|
||||||
rand.Read(s.hostKey)
|
rand.Read(s.hostKey)
|
||||||
@ -81,10 +73,13 @@ func TestAdminTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (s *AdminTestSuite) Test_AgentRegisters() {
|
func (s *AdminTestSuite) Test_AgentRegisters() {
|
||||||
publicId := "abc"
|
publicId := "abc"
|
||||||
|
agentRW, serverRW := s.createPipe()
|
||||||
testsupport.RunAndWait(
|
testsupport.RunAndWait(
|
||||||
&s.Suite,
|
&s.Suite,
|
||||||
func() any {
|
func() any {
|
||||||
agentConn, err := s.admin.AddAgent(s.hostKey, models.RendezVousId(publicId), comms.EnvironmentInfo{}, s.serverReadWriter)
|
agentConn, err := s.admin.AddAgent(
|
||||||
|
s.hostKey, models.RendezVousId(publicId), comms.EnvironmentInfo{},
|
||||||
|
serverRW)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
s.Equal(publicId, string(agentConn.Info.PublicId))
|
s.Equal(publicId, string(agentConn.Info.PublicId))
|
||||||
state := s.admin.CreateNotifification()
|
state := s.admin.CreateNotifification()
|
||||||
@ -95,12 +90,12 @@ func (s *AdminTestSuite) Test_AgentRegisters() {
|
|||||||
},
|
},
|
||||||
func() any {
|
func() any {
|
||||||
// verify registration message received
|
// verify registration message received
|
||||||
agentRegistration, err := comms.ReceiveRegistrationMessage(s.agentReadWriter)
|
agentRegistration, err := comms.ReceiveRegistrationMessage(agentRW)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
s.True(agentRegistration.Ok)
|
s.True(agentRegistration.Ok)
|
||||||
s.Equal(s.hostKey, agentRegistration.HostPrivateKey)
|
s.Equal(s.hostKey, agentRegistration.HostPrivateKey)
|
||||||
|
|
||||||
commChannel, err := comms.NewCommChannel(comms.Agent, s.agentReadWriter)
|
commChannel, err := comms.NewCommChannel(comms.Agent, agentRW)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
s.NotNil(commChannel)
|
s.NotNil(commChannel)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user