Skip to content

Commit de888b9

Browse files
author
Tsimafei Bredau
committed
fix now() function
1 parent d8e3533 commit de888b9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

bootstrap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func init() {
5555
}
5656

5757
func now() time.Time {
58-
return time.Unix(atomic.LoadInt64(&unixtime), 0)
58+
return time.Unix(0, atomic.LoadInt64(&unixtime))
5959
}
6060

6161
type bootstrap struct{}

bootstrap_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql/driver"
55
"reflect"
66
"testing"
7+
"time"
78
)
89

910
func Test_bootstrap_Open(t *testing.T) {
@@ -69,3 +70,27 @@ func TestOpen(t *testing.T) {
6970
})
7071
}
7172
}
73+
74+
func Test_now(t *testing.T) {
75+
tests := []struct {
76+
name string
77+
sleepDuration time.Duration
78+
want time.Time
79+
}{
80+
{
81+
name: "1 second",
82+
sleepDuration: time.Second,
83+
want: time.Unix(1, 0),
84+
},
85+
}
86+
for _, tt := range tests {
87+
t.Run(tt.name, func(t *testing.T) {
88+
time.Sleep(tt.sleepDuration)
89+
time.Sleep(time.Millisecond)
90+
got := now()
91+
if !got.Equal(tt.want) {
92+
t.Errorf("now() = %s, want %s", got.Format(time.RFC3339), tt.want.Format(time.RFC3339))
93+
}
94+
})
95+
}
96+
}

0 commit comments

Comments
 (0)