Skip to content

Commit cce04c1

Browse files
kolyshkingopherbot
authored andcommitted
go/packages: use t.Context
As it is pointed out in a comment added by CL 204200, let's switch to t.Context. Change-Id: I794702e1a7e0755e3fa4a4420f9d0b8919070428 Reviewed-on: https://go-review.googlesource.com/c/tools/+/703076 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Kirill Kolyshkin <kolyshkin@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 9310eb8 commit cce04c1

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

go/packages/packages_test.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package packages_test
66

77
import (
88
"bytes"
9-
"context"
109
"encoding/json"
11-
"flag"
1210
"fmt"
1311
"go/ast"
1412
constantpkg "go/constant"
@@ -25,7 +23,6 @@ import (
2523
"strings"
2624
"testing"
2725
"testing/fstest"
28-
"time"
2926

3027
"github.com/google/go-cmp/cmp"
3128
"golang.org/x/tools/go/packages"
@@ -36,25 +33,9 @@ import (
3633
"golang.org/x/tools/txtar"
3734
)
3835

39-
// testCtx is canceled when the test binary is about to time out.
40-
//
41-
// If https://golang.org/issue/28135 is accepted, uses of this variable in test
42-
// functions should be replaced by t.Context().
43-
var testCtx = context.Background()
44-
4536
func TestMain(m *testing.M) {
4637
testenv.ExitIfSmallMachine()
4738

48-
timeoutFlag := flag.Lookup("test.timeout")
49-
if timeoutFlag != nil {
50-
if d := timeoutFlag.Value.(flag.Getter).Get().(time.Duration); d != 0 {
51-
aBitShorter := d * 95 / 100
52-
var cancel context.CancelFunc
53-
testCtx, cancel = context.WithTimeout(testCtx, aBitShorter)
54-
defer cancel()
55-
}
56-
}
57-
5839
os.Exit(m.Run())
5940
}
6041

@@ -1924,7 +1905,7 @@ func TestLoadImportsC(t *testing.T) {
19241905
testenv.NeedsGoPackages(t)
19251906

19261907
cfg := &packages.Config{
1927-
Context: testCtx,
1908+
Context: t.Context(),
19281909
Mode: packages.LoadImports,
19291910
Tests: true,
19301911
}

0 commit comments

Comments
 (0)