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