Fixup test

This commit is contained in:
freddygv 2022-10-10 13:18:08 -06:00
parent 4f4112662e
commit bf72df7b0e
2 changed files with 21 additions and 4 deletions

View File

@ -351,10 +351,14 @@ func (s *Server) realHandleStream(streamReq HandleStreamRequest) error {
err := streamReq.Stream.Send(msg) err := streamReq.Stream.Send(msg)
sendMutex.Unlock() sendMutex.Unlock()
if err != nil { // We only track send successes and errors for response types because this is meant to track
status.TrackSendError(err.Error()) // resources, not request/ack messages.
} else { if msg.GetResponse() != nil {
status.TrackSendSuccess() if err != nil {
status.TrackSendError(err.Error())
} else {
status.TrackSendSuccess()
}
} }
return err return err
} }

View File

@ -572,9 +572,15 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
}) })
var lastSendAck time.Time var lastSendAck time.Time
var lastSendSuccess time.Time
client.DrainStream(t) client.DrainStream(t)
// Manually grab the last success time from sending the trust bundle or exported services list.
status, ok := srv.StreamStatus(testPeerID)
require.True(t, ok)
lastSendSuccess = status.LastSendSuccess
testutil.RunStep(t, "ack tracked as success", func(t *testing.T) { testutil.RunStep(t, "ack tracked as success", func(t *testing.T) {
ack := &pbpeerstream.ReplicationMessage{ ack := &pbpeerstream.ReplicationMessage{
Payload: &pbpeerstream.ReplicationMessage_Request_{ Payload: &pbpeerstream.ReplicationMessage_Request_{
@ -589,11 +595,13 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
} }
lastSendAck = it.FutureNow(1) lastSendAck = it.FutureNow(1)
err := client.Send(ack) err := client.Send(ack)
require.NoError(t, err) require.NoError(t, err)
expect := Status{ expect := Status{
Connected: true, Connected: true,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
ExportedServices: []string{}, ExportedServices: []string{},
} }
@ -631,6 +639,7 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
expect := Status{ expect := Status{
Connected: true, Connected: true,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
LastNack: lastNack, LastNack: lastNack,
LastNackMessage: lastNackMsg, LastNackMessage: lastNackMsg,
@ -682,6 +691,7 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
expect := Status{ expect := Status{
Connected: true, Connected: true,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
LastNack: lastNack, LastNack: lastNack,
LastNackMessage: lastNackMsg, LastNackMessage: lastNackMsg,
@ -737,6 +747,7 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
expect := Status{ expect := Status{
Connected: true, Connected: true,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
LastNack: lastNack, LastNack: lastNack,
LastNackMessage: lastNackMsg, LastNackMessage: lastNackMsg,
@ -766,6 +777,7 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
expect := Status{ expect := Status{
Connected: true, Connected: true,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
LastNack: lastNack, LastNack: lastNack,
LastNackMessage: lastNackMsg, LastNackMessage: lastNackMsg,
@ -793,6 +805,7 @@ func TestStreamResources_Server_StreamTracker(t *testing.T) {
expect := Status{ expect := Status{
Connected: false, Connected: false,
DisconnectErrorMessage: lastRecvErrorMsg, DisconnectErrorMessage: lastRecvErrorMsg,
LastSendSuccess: lastSendSuccess,
LastAck: lastSendAck, LastAck: lastSendAck,
LastNack: lastNack, LastNack: lastNack,
LastNackMessage: lastNackMsg, LastNackMessage: lastNackMsg,