]> Cypherpunks repositories - gostls13.git/commitdiff
synctest: fix comments for time.Now() in synctests
authorChristian Hoeppner <hoeppi@google.com>
Fri, 4 Jul 2025 18:40:42 +0000 (18:40 +0000)
committerDamien Neil <dneil@google.com>
Thu, 10 Jul 2025 20:16:07 +0000 (13:16 -0700)
Also add a test case to make sure that time.Now() results in the
documented date.

Change-Id: Ic4cc577eba485b7c6e1a64122da06d7075bbe12e
Reviewed-on: https://go-review.googlesource.com/c/go/+/685677
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Christian Höppner <hoeppi@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/testing/synctest/example_test.go
src/testing/synctest/synctest.go
src/testing/synctest/synctest_test.go

index 9ecd28d3dd452b01bc331f85238e803c9f0f9b73..843377ea88ef7193b2ad9f942aed28ca760d6854 100644 (file)
@@ -21,7 +21,7 @@ import (
 
 func TestTime(t *testing.T) {
        synctest.Test(t, func(t *testing.T) {
-               start := time.Now() // always midnight UTC 2001-01-01
+               start := time.Now() // always midnight UTC 2000-01-01
                go func() {
                        time.Sleep(1 * time.Nanosecond)
                        t.Log(time.Since(start)) // always logs "1ns"
index 0911519aab41caee58edcac6ab167bf90efe591e..ff88c3ec42a98107631c0f9cec50cd8be45fff55 100644 (file)
@@ -22,7 +22,7 @@
 //
 //     func TestTime(t *testing.T) {
 //             synctest.Test(t, func(t *testing.T) {
-//                     start := time.Now() // always midnight UTC 2001-01-01
+//                     start := time.Now() // always midnight UTC 2000-01-01
 //                     go func() {
 //                             time.Sleep(1 * time.Second)
 //                             t.Log(time.Since(start)) // always logs "1s"
index 9c731787509fecab2869ad668f481936d3ccaaad..62f10d1b819b13ad2e346d7e2b460b7d51da95dd 100644 (file)
@@ -11,6 +11,7 @@ import (
        "regexp"
        "testing"
        "testing/synctest"
+       "time"
 )
 
 // Tests for interactions between synctest bubbles and the testing package.
@@ -179,3 +180,11 @@ func runTest(t *testing.T, args []string, f func(), pattern string) {
                t.Errorf("got output:\n%s\nwant matching:\n%s", out, pattern)
        }
 }
+
+func TestNow(t *testing.T) {
+       synctest.Test(t, func(t *testing.T) {
+               if got, want := time.Now(), time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC); !got.Equal(want) {
+                       t.Errorf("time.Now() = %v, want %v", got, want)
+               }
+       })
+}