File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,10 @@ func AccessTime() int64 {
7777 // Return last updated time.
7878 v := utime .Load ()
7979 if v == 0 {
80- panic ("access time service not running" )
80+ // Always register a time, the worst case is a stale time.
81+ // On startup, we can register in parallel and could previously panic.
82+ v = time .Now ().UnixNano ()
83+ utime .Store (v )
8184 }
8285 return v
8386}
Original file line number Diff line number Diff line change @@ -19,15 +19,18 @@ import (
1919 "time"
2020)
2121
22- func TestNotRunningPanic (t * testing.T ) {
23- defer func () {
24- if r := recover (); r == nil {
25- t .Errorf ("Expected function to panic, but it did not" )
26- }
27- }()
22+ func TestNotRunningValue (t * testing.T ) {
2823 // Set back to zero in case this test gets run multiple times via --count.
2924 utime .Store (0 )
30- _ = AccessTime ()
25+ at := AccessTime ()
26+ if at == 0 {
27+ t .Fatal ("Expected non-zero access time" )
28+ }
29+
30+ atn := AccessTime ()
31+ if atn != at {
32+ t .Fatal ("Did not expect updates to access time" )
33+ }
3134}
3235
3336func TestRegisterAndUnregister (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments