aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-03-12 16:00:26 -0700
committerGopher Robot <gobot@golang.org>2025-03-18 10:50:51 -0700
commit5916bc5b5796e8fd15f3b4e95c945f5f4933e1d5 (patch)
tree0de2e9af22d47a73b1099d484a17ffe47a8d88c8 /src/internal
parent069471838998c304ac751b031a19283a9ad30bdb (diff)
downloadgo-5916bc5b5796e8fd15f3b4e95c945f5f4933e1d5.tar.xz
runtime, time: don't use monotonic clock inside synctest bubbles
Don't include a monotonic time in time.Times created inside a bubble, to avoid the confusion of different Times using different monotonic clock epochs. For #67434 goos: darwin goarch: arm64 pkg: time cpu: Apple M1 Pro │ /tmp/bench.0 │ /tmp/bench.1 │ │ sec/op │ sec/op vs base │ Since-10 18.42n ± 2% 18.68n ± 1% ~ (p=0.101 n=10) Until-10 18.28n ± 2% 18.46n ± 2% +0.98% (p=0.009 n=10) geomean 18.35n 18.57n +1.20% Change-Id: Iaf1b80d0a4df52139c5b80d4bde4410ef8a49f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/657415 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/synctest/synctest_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/internal/synctest/synctest_test.go b/src/internal/synctest/synctest_test.go
index 450d5f5416..62acb42359 100644
--- a/src/internal/synctest/synctest_test.go
+++ b/src/internal/synctest/synctest_test.go
@@ -37,6 +37,27 @@ func TestNow(t *testing.T) {
})
}
+// TestMonotonicClock exercises comparing times from within a bubble
+// with ones from outside the bubble.
+func TestMonotonicClock(t *testing.T) {
+ start := time.Now()
+ synctest.Run(func() {
+ time.Sleep(time.Until(start.Round(0)))
+ if got, want := time.Now().In(time.UTC), start.In(time.UTC); !got.Equal(want) {
+ t.Fatalf("time.Now() = %v, want %v", got, want)
+ }
+
+ wait := 1 * time.Second
+ time.Sleep(wait)
+ if got := time.Since(start); got != wait {
+ t.Fatalf("time.Since(start) = %v, want %v", got, wait)
+ }
+ if got := time.Now().Sub(start); got != wait {
+ t.Fatalf("time.Now().Sub(start) = %v, want %v", got, wait)
+ }
+ })
+}
+
func TestRunEmpty(t *testing.T) {
synctest.Run(func() {
})