1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package time 6 7 func init() { 8 // force US/Pacific for time zone tests 9 ForceUSPacificForTesting() 10 } 11 12 var Interrupt = interrupt 13 var DaysIn = daysIn 14 15 func empty(arg interface{}, seq uintptr) {} 16 17 // Test that a runtimeTimer with a duration so large it overflows 18 // does not cause other timers to hang. 19 // 20 // This test has to be in internal_test.go since it fiddles with 21 // unexported data structures. 22 func CheckRuntimeTimerOverflow() { 23 // We manually create a runtimeTimer to bypass the overflow 24 // detection logic in NewTimer: we're testing the underlying 25 // runtime.addtimer function. 26 r := &runtimeTimer{ 27 when: runtimeNano() + (1<<63 - 1), 28 f: empty, 29 arg: nil, 30 } 31 startTimer(r) 32 33 // Start a goroutine that should send on t.C right away. 34 t := NewTimer(1) 35 36 defer func() { 37 // Subsequent tests won't work correctly if we don't stop the 38 // overflow timer and kick the timer proc back into service. 39 // 40 // The timer proc is now sleeping and can only be awoken by 41 // adding a timer to the *beginning* of the heap. We can't 42 // wake it up by calling NewTimer since other tests may have 43 // left timers running that should have expired before ours. 44 // Instead we zero the overflow timer duration and start it 45 // once more. 46 stopTimer(r) 47 t.Stop() 48 r.when = 0 49 startTimer(r) 50 }() 51 52 // If the test fails, we will hang here until the timeout in the testing package 53 // fires, which is 10 minutes. It would be nice to catch the problem sooner, 54 // but there is no reliable way to guarantee that timerproc schedules without 55 // doing something involving timerproc itself. Previous failed attempts have 56 // tried calling runtime.Gosched and runtime.GC, but neither is reliable. 57 // So we fall back to hope: We hope we don't hang here. 58 <-t.C 59 } 60