-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.
Milestone
Description
Go version
tip
Output of go env in your module/workspace:
Not relevantWhat did you do?
The documentation for testing/synctest at tip.golang.org says:
For example, this test runs immediately rather than taking two seconds:
func TestTime(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
start := time.Now() // always midnight UTC 2001-01-01
go func() {
time.Sleep(1 * time.Nanosecond)
t.Log(time.Since(start)) // always logs "1ns"
}()
time.Sleep(2 * time.Nanosecond) // the goroutine above will run before this Sleep returns
t.Log(time.Since(start)) // always logs "2ns"
})
}
It is possible I am not very smart, and just totally misreading this. But I am confused how this could ever take two seconds to run, under normal conditions - the maximum sleep introduced is 2 nanoseconds, and the rest of the code should complete reasonably quickly (on the order of microseconds or milliseconds).
As a result, I'm not sure how synctest modifies the typical behavior of the program.
What did you see happen?
See above
What did you expect to see?
See above
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.