Skip to content

Commit

Permalink
backport subtle test fix from #16396
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed May 10, 2023
1 parent 0997ddf commit 921c184
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agent/grpc-external/services/peerstream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,8 @@ func TestStreamResources_Server_DisconnectsOnHeartbeatTimeout(t *testing.T) {
})

testutil.RunStep(t, "stream is disconnected due to heartbeat timeout", func(t *testing.T) {
disconnectTime := it.FutureNow(1)
retry.Run(t, func(r *retry.R) {
disconnectTime := it.StaticNow()
status, ok := srv.StreamStatus(testPeerID)
require.True(r, ok)
require.False(r, status.Connected)
Expand Down
10 changes: 10 additions & 0 deletions agent/grpc-external/services/peerstream/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ func (t *incrementalTime) Now() time.Time {
return t.base.Add(dur)
}

// StaticNow returns the current internal clock without advancing it.
func (t *incrementalTime) StaticNow() time.Time {
t.mu.Lock()
defer t.mu.Unlock()

dur := time.Duration(t.next) * time.Second

return t.base.Add(dur)
}

// FutureNow will return a given future value of the Now() function.
// The numerical argument indicates which future Now value you wanted. The
// value must be > 0.
Expand Down

0 comments on commit 921c184

Please sign in to comment.