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: bug with httptest #71345

Closed
stamm opened this issue Jan 20, 2025 · 2 comments
Closed

testing/synctest: bug with httptest #71345

stamm opened this issue Jan 20, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@stamm
Copy link

stamm commented Jan 20, 2025

Go version

go version go1.24rc2 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='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/stamm/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/stamm/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/49/hzj818h119v6ytm3q2kt26_m0000gp/T/go-build3316532799=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/stamm/code/github.com/stamm/go-conc/go.mod'
GOMODCACHE='/Users/stamm/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/stamm/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go_versions/current'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/stamm/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go_versions/current/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24rc2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package tsync

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"testing"
	"testing/synctest"
	"time"
)

func TestSyncTest(t *testing.T) {
	t.Parallel()
	const sleepTime = 1 * time.Second
	synctest.Run(func() {
		ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			time.Sleep(sleepTime)
			fmt.Fprintln(w, "Hello")
		}))
		defer ts.Close()

		before := time.Now()
		http.Get(ts.URL)
		after := time.Now()
		d := after.Sub(before)
		if d != sleepTime {
			t.Fatalf("took %v", d)
		}
	})
}

What did you see happen?

❯ env GOEXPERIMENT=synctest go test -timeout 2s ./...
panic: test timed out after 2s
        running tests:
                TestSyncTest (2s)

goroutine 2 [running]:
testing.(*M).startAlarm.func1()
        /usr/local/go_versions/current/src/testing/testing.go:2484 +0x308
created by time.goFunc
        /usr/local/go_versions/current/src/time/sleep.go:215 +0x38
...

What did you expect to see?

I expect to pass the test, not run infinite time. In this case abort by timeout

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 20, 2025
@seankhliao
Copy link
Member

#67434 the docs for Wait include:

// A goroutine blocked on an I/O operation, such as a read from a network connection,
// is not idle. Tests which operate on a net.Conn or similar type should use an
// in-memory implementation rather than a real network connection.

I don't think there's much to do here.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants