Fix flaky Test_ActivityTimeouts
@@ -468,9 +468,22 @@ func (s *clientIntegrationSuite) Test_ActivityTimeouts() {
info := activity.GetInfo(ctx)
if info.ActivityID == "Heartbeat" {
go func() {
+ // NOTE: due to client side heartbeat batching, heartbeat may be sent
+ // later than expected.
+ // e.g. if activity heartbeat timeout is 2s,
+ // and we call RecordHeartbeat() at 0s, 0.5s, 1s, 1.5s
+ // the client by default will send two heartbeats at 0s and 2*0.8=1.6s
+ // Now if when running the test, this heartbeat goroutine becomes slow,
+ // and call RecordHeartbeat() after 1.6s, then that heartbeat will be sent
+ // to server at 3.2s (the next batch).
+ // Since the entire activity will finish at 5s, there won't be
+ // any heartbeat timeout error.
+ // so here, we reduce the duration between two heartbeats, so that they are
+ // more likey be sent in the heartbeat batch at 1.6s
+ // (basically increasing the room for delay in heartbeat goroutine from 0.1s to 1s)
for i := 0; i < 4; i++ {
activity.RecordHeartbeat(ctx, i)
- time.Sleep(500 * time.Millisecond)
+ time.Sleep(200 * time.Millisecond)
}
}()
}
