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/synctest: panic with time.NewTimer #70741

Closed
codekitchen opened this issue Dec 9, 2024 · 4 comments
Closed

testing/synctest: panic with time.NewTimer #70741

codekitchen opened this issue Dec 9, 2024 · 4 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@codekitchen
Copy link
Contributor

Go version

go version devel go1.24-312f7c1bd3 Fri Dec 6 21:15:30 2024 +0000 X:synctest 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/brianp/Library/Caches/go-build'
GODEBUG=''
GOENV='/Users/brianp/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT='synctest'
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/n6/9stkk73j37n0zj9sqfsq63240000gn/T/go-build2814904191=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/brianp/p/test/go.mod'
GOMODCACHE='/Users/brianp/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/brianp/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/brianp/p/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/brianp/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/brianp/p/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.24-312f7c1bd3 Fri Dec 6 21:15:30 2024 +0000 X:synctest'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I've been kicking the tires on the experimental testing/synctest feature. I have converted a few tests to use it successfully. But I am running into a panic issue: any test case that uses time.NewTimer or time.After and then time.Sleep panics, for example

func TestNewTimerCrashes(t *testing.T) {
	synctest.Run(func() {
		t1 := time.NewTimer(time.Second)
		time.Sleep(2 * time.Second)
		<-t1.C
	})
}

What did you see happen?

panic: timer moved between synctest groups

What did you expect to see?

I would expect this test to succeed, pretty much immediately due to synctest stubbing out the Sleep.

If I use time.NewTicker instead, then it does succeed, as long as I Stop() that ticker (see this other issue)

@codekitchen codekitchen changed the title testing/synctest: panic with timer.NewTimer testing/synctest: panic with time.NewTimer Dec 9, 2024
@ianlancetaylor
Copy link
Member

CC @neild

@neild neild self-assigned this Dec 9, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/634955 mentions this issue: runtime: avoid panic in expired synctest timer chan read

@neild
Copy link
Contributor

neild commented Dec 11, 2024

Thanks for the report! Should be fixed now.

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 11, 2024
@dmitshur dmitshur added this to the Go1.24 milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants