Skip to content

Commit

Permalink
br: cancel context when timer stop (#56948) (#57006)
Browse files Browse the repository at this point in the history
ref #53480
  • Loading branch information
ti-chi-bot authored Oct 30, 2024
1 parent 1c3d94c commit 1838458
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion br/pkg/backup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ go_test(
embed = [":backup"],
flaky = True,
race = "on",
shard_count = 14,
shard_count = 15,
deps = [
"//br/pkg/conn",
"//br/pkg/gluetidb/mock",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/backup/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (trecv *timeoutRecv) Refresh() {
func (trecv *timeoutRecv) Stop() {
close(trecv.refresh)
trecv.wg.Wait()
trecv.cancel(nil)
}

var TimeoutOneResponse = time.Hour
Expand Down
10 changes: 10 additions & 0 deletions br/pkg/backup/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ func TestTimeoutRecvCancel(t *testing.T) {
cancel()
trecv.wg.Wait()
}

func TestTimeoutRecvCanceled(t *testing.T) {
ctx := context.Background()
cctx, cancel := context.WithCancel(ctx)
defer cancel()

tctx, trecv := StartTimeoutRecv(cctx, time.Hour)
trecv.Stop()
require.Equal(t, "context canceled", tctx.Err().Error())
}

0 comments on commit 1838458

Please sign in to comment.