Skip to content

Commit

Permalink
backport subtle test fix from #15252
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed May 10, 2023
1 parent 86755d0 commit 1fd752d
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 @@ -1252,8 +1252,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 @@ -150,6 +150,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 1fd752d

Please sign in to comment.