Skip to content

Commit aa5de9e

Browse files
hoeppi-googleneild
authored andcommitted
synctest: fix comments for time.Now() in synctests
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>
1 parent 63ec70d commit aa5de9e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/testing/synctest/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
func TestTime(t *testing.T) {
2323
synctest.Test(t, func(t *testing.T) {
24-
start := time.Now() // always midnight UTC 2001-01-01
24+
start := time.Now() // always midnight UTC 2000-01-01
2525
go func() {
2626
time.Sleep(1 * time.Nanosecond)
2727
t.Log(time.Since(start)) // always logs "1ns"

src/testing/synctest/synctest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//
2323
// func TestTime(t *testing.T) {
2424
// synctest.Test(t, func(t *testing.T) {
25-
// start := time.Now() // always midnight UTC 2001-01-01
25+
// start := time.Now() // always midnight UTC 2000-01-01
2626
// go func() {
2727
// time.Sleep(1 * time.Second)
2828
// t.Log(time.Since(start)) // always logs "1s"

src/testing/synctest/synctest_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"regexp"
1212
"testing"
1313
"testing/synctest"
14+
"time"
1415
)
1516

1617
// 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) {
179180
t.Errorf("got output:\n%s\nwant matching:\n%s", out, pattern)
180181
}
181182
}
183+
184+
func TestNow(t *testing.T) {
185+
synctest.Test(t, func(t *testing.T) {
186+
if got, want := time.Now(), time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC); !got.Equal(want) {
187+
t.Errorf("time.Now() = %v, want %v", got, want)
188+
}
189+
})
190+
}

0 commit comments

Comments
 (0)