Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: B.Context returns nil context #70866

Closed
artyom opened this issue Dec 16, 2024 · 3 comments
Closed

testing: B.Context returns nil context #70866

artyom opened this issue Dec 16, 2024 · 3 comments

Comments

@artyom
Copy link
Member

artyom commented Dec 16, 2024

Go version

go version go1.24rc1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/artyom/Library/Caches/go-build'
GODEBUG=''
GOENV='/Users/artyom/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-ldflags=-w -trimpath'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/lb/3rk8rqs53czgb4v35w_342xc0000gn/T/go-build3751872123=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/artyom/repos/example/go.mod'
GOMODCACHE='/Users/artyom/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/artyom/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/artyom/Library/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/artyom/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/artyom/Library/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24rc1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

https://go.dev/play/p/A-SjUqygxkd?v=gotip

Tried to use testing.T.Context and testing.B.Context

func TestSomething(t *testing.T) {
	if t.Context() == nil {
		t.Fatal("nil context")
	}
}

func BenchmarkSomething(b *testing.B) {
	ctx := b.Context()
	for b.Loop() {
		if ctx == nil {
			b.Fatal("nil context")
		}
	}
}

What did you see happen?

testing.T.Context returns non-nil context (as expected), but testing.B.Context returns nil context

What did you expect to see?

Both t.Context() and b.Context() returning a non-nil context

@gabyhelp
Copy link

@seankhliao seankhliao added this to the Go1.24 milestone Dec 16, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/637236 mentions this issue: testing: support B.Context and F.Context

@ianlancetaylor
Copy link
Member

I've sent a CL to fix this. On that CL I've raised the issue that #36532 only accepted T.Context, not B.Context.

wyf9661 pushed a commit to wyf9661/go that referenced this issue Jan 21, 2025
CL 603959 added T.Context for golang#36532.

The discussion on the proposal only mentions t.Context.
However, the implementation of CL 603959 also added B.Context and F.Context.
They were added to the API listing, and B.Context was mentioned in
the release notes.

Unfortunately, the new B.Context and F.Context methods always
returned nil, rather than a context.Context value.

This change adds a working implementation of B.Context and F.Context.

For golang#36532
Fixes golang#70866

Change-Id: I8a44e6649fb658e4f641ffb7efd08b4374f578ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/637236
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants