mirror of
https://github.com/golang/go
synced 2024-11-17 19:04:47 -07:00
cmd/go: add tracing instrumentation to load.TestPackagesFor
This change adds tracing instrumentation into load.TestPackagesFor, propagating context through its callers. Updates #38714 Change-Id: I80fefaf3116ccccffaa8bb7613a656bda867394c Reviewed-on: https://go-review.googlesource.com/c/go/+/248323 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
15b98e55d1
commit
38fea3a4ec
@ -477,9 +477,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
|
||||
var pmain, ptest, pxtest *load.Package
|
||||
var err error
|
||||
if *listE {
|
||||
pmain, ptest, pxtest = load.TestPackagesAndErrors(p, nil)
|
||||
pmain, ptest, pxtest = load.TestPackagesAndErrors(ctx, p, nil)
|
||||
} else {
|
||||
pmain, ptest, pxtest, err = load.TestPackagesFor(p, nil)
|
||||
pmain, ptest, pxtest, err = load.TestPackagesFor(ctx, p, nil)
|
||||
if err != nil {
|
||||
base.Errorf("can't load test package: %s", err)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package load
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cmd/go/internal/str"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
@ -20,6 +20,9 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"cmd/go/internal/str"
|
||||
"cmd/go/internal/trace"
|
||||
)
|
||||
|
||||
var TestMainDeps = []string{
|
||||
@ -42,8 +45,8 @@ type TestCover struct {
|
||||
// TestPackagesFor is like TestPackagesAndErrors but it returns
|
||||
// an error if the test packages or their dependencies have errors.
|
||||
// Only test packages without errors are returned.
|
||||
func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Package, err error) {
|
||||
pmain, ptest, pxtest = TestPackagesAndErrors(p, cover)
|
||||
func TestPackagesFor(ctx context.Context, p *Package, cover *TestCover) (pmain, ptest, pxtest *Package, err error) {
|
||||
pmain, ptest, pxtest = TestPackagesAndErrors(ctx, p, cover)
|
||||
for _, p1 := range []*Package{ptest, pxtest, pmain} {
|
||||
if p1 == nil {
|
||||
// pxtest may be nil
|
||||
@ -89,7 +92,10 @@ func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Packag
|
||||
//
|
||||
// The caller is expected to have checked that len(p.TestGoFiles)+len(p.XTestGoFiles) > 0,
|
||||
// or else there's no point in any of this.
|
||||
func TestPackagesAndErrors(p *Package, cover *TestCover) (pmain, ptest, pxtest *Package) {
|
||||
func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (pmain, ptest, pxtest *Package) {
|
||||
ctx, span := trace.StartSpan(ctx, "load.TestPackagesAndErrors")
|
||||
defer span.Done()
|
||||
|
||||
pre := newPreload()
|
||||
defer pre.flush()
|
||||
allImports := append([]string{}, p.TestImports...)
|
||||
|
@ -746,7 +746,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
|
||||
ensureImport(p, "sync/atomic")
|
||||
}
|
||||
|
||||
buildTest, runTest, printTest, err := builderTest(&b, p)
|
||||
buildTest, runTest, printTest, err := builderTest(&b, ctx, p)
|
||||
if err != nil {
|
||||
str := err.Error()
|
||||
str = strings.TrimPrefix(str, "\n")
|
||||
@ -813,7 +813,7 @@ var windowsBadWords = []string{
|
||||
"update",
|
||||
}
|
||||
|
||||
func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, printAction *work.Action, err error) {
|
||||
func builderTest(b *work.Builder, ctx context.Context, p *load.Package) (buildAction, runAction, printAction *work.Action, err error) {
|
||||
if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
|
||||
build := b.CompileAction(work.ModeBuild, work.ModeBuild, p)
|
||||
run := &work.Action{Mode: "test run", Package: p, Deps: []*work.Action{build}}
|
||||
@ -836,7 +836,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
|
||||
DeclVars: declareCoverVars,
|
||||
}
|
||||
}
|
||||
pmain, ptest, pxtest, err := load.TestPackagesFor(p, cover)
|
||||
pmain, ptest, pxtest, err := load.TestPackagesFor(ctx, p, cover)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func runVet(ctx context.Context, cmd *base.Command, args []string) {
|
||||
|
||||
root := &work.Action{Mode: "go vet"}
|
||||
for _, p := range pkgs {
|
||||
_, ptest, pxtest, err := load.TestPackagesFor(p, nil)
|
||||
_, ptest, pxtest, err := load.TestPackagesFor(ctx, p, nil)
|
||||
if err != nil {
|
||||
base.Errorf("%v", err)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user