Skip to content

Commit 5640a98

Browse files
Fix some lostcancel errors (#3764)
1 parent 4e8601a commit 5640a98

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

common/quotas/multi_rate_limiter_impl_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ func (s *multiStageRateLimiterSuite) TestWaitN_AlreadyExpired() {
199199
}
200200

201201
func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_Error() {
202-
ctx, _ := context.WithTimeout(context.Background(), time.Second)
202+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
203+
defer cancel()
203204
numToken := 4
204205

205206
firstReservationDelay := 2 * time.Second
@@ -244,7 +245,8 @@ func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_Cancell
244245
}
245246

246247
func (s *multiStageRateLimiterSuite) TestWaitN_NotExpired_WithExpiration_NoError() {
247-
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
248+
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
249+
defer cancel()
248250
numToken := 4
249251

250252
firstReservationDelay := 2 * time.Second

common/quotas/priority_rate_limiter_impl_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_AlreadyExpired() {
254254
}
255255

256256
func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExpiration_Error() {
257-
ctx, _ := context.WithTimeout(context.Background(), time.Second)
257+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
258+
defer cancel()
258259
token := 1
259260
req := Request{
260261
API: s.highPriorityAPIName,
@@ -277,7 +278,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExp
277278
}
278279

279280
func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpiration_Error() {
280-
ctx, _ := context.WithTimeout(context.Background(), time.Second)
281+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
282+
defer cancel()
281283
token := 1
282284
req := Request{
283285
API: s.lowPriorityAPIName,
@@ -350,7 +352,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpi
350352
}
351353

352354
func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExpiration_NoError() {
353-
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
355+
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
356+
defer cancel()
354357
token := 1
355358
req := Request{
356359
API: s.highPriorityAPIName,
@@ -371,7 +374,8 @@ func (s *priorityStageRateLimiterSuite) TestWait_HighPriority_NotExpired_WithExp
371374
}
372375

373376
func (s *priorityStageRateLimiterSuite) TestWait_LowPriority_NotExpired_WithExpiration_NoError() {
374-
ctx, _ := context.WithTimeout(context.Background(), 4*time.Second)
377+
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
378+
defer cancel()
375379
token := 1
376380
req := Request{
377381
API: s.lowPriorityAPIName,

common/rpc/context_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ func (s *contextSuite) TestCopyContextValues_ValueCopied() {
6161
ctx = metadata.NewIncomingContext(ctx, metadata.Pairs(metadataKey, metadataValue))
6262

6363
newDeadline := time.Now().Add(time.Hour)
64-
newContext, _ := context.WithDeadline(context.Background(), newDeadline)
64+
newContext, cancel := context.WithDeadline(context.Background(), newDeadline)
65+
defer cancel()
6566

6667
newContext = CopyContextValues(newContext, ctx)
6768

service/frontend/workflow_handler_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,8 @@ func listArchivedWorkflowExecutionsTestRequest() *workflowservice.ListArchivedWo
25762576
func TestContextNearDeadline(t *testing.T) {
25772577
assert.False(t, contextNearDeadline(context.Background(), longPollTailRoom))
25782578

2579-
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*500)
2579+
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
2580+
defer cancel()
25802581
assert.True(t, contextNearDeadline(ctx, longPollTailRoom))
25812582
assert.False(t, contextNearDeadline(ctx, time.Millisecond))
25822583
}

0 commit comments

Comments
 (0)