Skip to content

Commit

Permalink
Fix some lostcancel errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSnowden committed Dec 27, 2022
1 parent 7d66087 commit cb2ab18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions common/quotas/multi_rate_limiter_impl_test.go
Expand Up @@ -199,7 +199,8 @@ func (s *multiStageRateLimiterSuite) TestWaitN_AlreadyExpired() {
}

func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_Error() {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
numToken := 4

firstReservationDelay := 2 * time.Second
Expand Down Expand Up @@ -244,7 +245,8 @@ func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_Cancell
}

func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_NoError() {
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
numToken := 4

firstReservationDelay := 2 * time.Second
Expand Down
12 changes: 8 additions & 4 deletions common/quotas/priority_rate_limiter_impl_test.go
Expand Up @@ -254,7 +254,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_AlreadyExpired() {
}

func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExpiration_Error() {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
token := 1
req := Request{
API: s.highPriorityAPIName,
Expand All @@ -277,7 +278,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExp
}

func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpiration_Error() {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
token := 1
req := Request{
API: s.lowPriorityAPIName,
Expand Down Expand Up @@ -350,7 +352,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpi
}

func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExpiration_NoError() {
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
token := 1
req := Request{
API: s.highPriorityAPIName,
Expand All @@ -371,7 +374,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExp
}

func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpiration_NoError() {
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
token := 1
req := Request{
API: s.lowPriorityAPIName,
Expand Down
3 changes: 2 additions & 1 deletion common/rpc/context_test.go
Expand Up @@ -61,7 +61,8 @@ func (s *contextSuite) TestCopyContextValues_ValueCopied() {
ctx = metadata.NewIncomingContext(ctx, metadata.Pairs(metadataKey, metadataValue))

newDeadline := time.Now().Add(time.Hour)
newContext, _ := context.WithDeadline(context.Background(), newDeadline)
newContext, cancel := context.WithDeadline(context.Background(), newDeadline)
defer cancel()

newContext = CopyContextValues(newContext, ctx)

Expand Down
3 changes: 2 additions & 1 deletion service/frontend/workflow_handler_test.go
Expand Up @@ -2576,7 +2576,8 @@ func listArchivedWorkflowExecutionsTestRequest() *workflowservice.ListArchivedWo
func TestContextNearDeadline(t *testing.T) {
assert.False(t, contextNearDeadline(context.Background(), longPollTailRoom))

ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*500)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
defer cancel()
assert.True(t, contextNearDeadline(ctx, longPollTailRoom))
assert.False(t, contextNearDeadline(ctx, time.Millisecond))
}
Expand Down

0 comments on commit cb2ab18

Please sign in to comment.