diff --git a/common/quotas/multi_rate_limiter_impl_test.go b/common/quotas/multi_rate_limiter_impl_test.go index 1f2514e8e67..296245c896f 100644 --- a/common/quotas/multi_rate_limiter_impl_test.go +++ b/common/quotas/multi_rate_limiter_impl_test.go @@ -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 @@ -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 diff --git a/common/quotas/priority_rate_limiter_impl_test.go b/common/quotas/priority_rate_limiter_impl_test.go index e10943d057a..48de907e550 100644 --- a/common/quotas/priority_rate_limiter_impl_test.go +++ b/common/quotas/priority_rate_limiter_impl_test.go @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/common/rpc/context_test.go b/common/rpc/context_test.go index db0dd2b148a..4d0215bca99 100644 --- a/common/rpc/context_test.go +++ b/common/rpc/context_test.go @@ -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) diff --git a/service/frontend/workflow_handler_test.go b/service/frontend/workflow_handler_test.go index a8f08feead3..da9ed51ea12 100644 --- a/service/frontend/workflow_handler_test.go +++ b/service/frontend/workflow_handler_test.go @@ -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)) }