Skip to content

Commit 7ebabfe

Browse files
kolyshkingopherbot
authored andcommitted
gopls/internal/progress: use t.Context in tests
This case was not recognized by modernize tool (probably because ctx is not being initialized locally, but comes from setup()), so fix this manually. Change-Id: I135a3255a903689aee619b16a3fe16699459300a Reviewed-on: https://go-review.googlesource.com/c/tools/+/703078 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Kirill Kolyshkin <[email protected]> Reviewed-by: Mark Freeman <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent baefe5a commit 7ebabfe

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

gopls/internal/progress/progress_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func (c *fakeClient) ShowMessage(context.Context, *protocol.ShowMessageParams) e
6363
return nil
6464
}
6565

66-
func setup() (context.Context, *Tracker, *fakeClient) {
66+
func setup() (*Tracker, *fakeClient) {
6767
c := &fakeClient{}
6868
tracker := NewTracker(c)
6969
tracker.SetSupportsWorkDoneProgress(true)
70-
return context.Background(), tracker, c
70+
return tracker, c
7171
}
7272

7373
func TestProgressTracker_Reporting(t *testing.T) {
@@ -108,9 +108,8 @@ func TestProgressTracker_Reporting(t *testing.T) {
108108
},
109109
} {
110110
t.Run(test.name, func(t *testing.T) {
111-
ctx, tracker, client := setup()
112-
ctx, cancel := context.WithCancel(ctx)
113-
defer cancel()
111+
tracker, client := setup()
112+
ctx := t.Context()
114113
tracker.supportsWorkDoneProgress = test.supported
115114
work := tracker.Start(ctx, "work", "message", test.token, nil)
116115
client.mu.Lock()
@@ -146,10 +145,10 @@ func TestProgressTracker_Reporting(t *testing.T) {
146145

147146
func TestProgressTracker_Cancellation(t *testing.T) {
148147
for _, token := range []protocol.ProgressToken{nil, 1, "a"} {
149-
ctx, tracker, _ := setup()
148+
tracker, _ := setup()
150149
var canceled bool
151150
cancel := func() { canceled = true }
152-
work := tracker.Start(ctx, "work", "message", token, cancel)
151+
work := tracker.Start(t.Context(), "work", "message", token, cancel)
153152
if err := tracker.Cancel(work.Token()); err != nil {
154153
t.Fatal(err)
155154
}

0 commit comments

Comments
 (0)