Skip to content

testing/synctest: bug with httptest #71345

@stamm

Description

@stamm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions