2011-10-27 01:57:58 +02:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package time
|
|
|
|
|
2018-01-09 02:23:08 +01:00
|
|
|
import "runtime"
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func init() {
|
|
|
|
// force US/Pacific for time zone tests
|
2013-01-29 21:52:43 +01:00
|
|
|
ForceUSPacificForTesting()
|
2011-10-27 01:57:58 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 02:23:08 +01:00
|
|
|
func initTestingZone() {
|
|
|
|
z, err := loadLocation("America/Los_Angeles", zoneSources[len(zoneSources)-1:])
|
|
|
|
if runtime.Compiler == "gccgo" && err != nil {
|
|
|
|
z, err = loadLocation("America/Los_Angeles", zoneSources)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
panic("cannot load America/Los_Angeles for testing: " + err.Error())
|
|
|
|
}
|
|
|
|
z.name = "Local"
|
|
|
|
localLoc = *z
|
|
|
|
}
|
|
|
|
|
|
|
|
var OrigZoneSources = zoneSources
|
|
|
|
|
|
|
|
func forceZipFileForTesting(zipOnly bool) {
|
|
|
|
zoneSources = make([]string, len(OrigZoneSources))
|
|
|
|
copy(zoneSources, OrigZoneSources)
|
|
|
|
if zipOnly {
|
|
|
|
zoneSources = zoneSources[len(zoneSources)-1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
var Interrupt = interrupt
|
2012-01-12 02:31:45 +01:00
|
|
|
var DaysIn = daysIn
|
2013-11-06 20:49:01 +01:00
|
|
|
|
2015-01-15 01:27:56 +01:00
|
|
|
func empty(arg interface{}, seq uintptr) {}
|
2013-11-06 20:49:01 +01:00
|
|
|
|
|
|
|
// Test that a runtimeTimer with a duration so large it overflows
|
|
|
|
// does not cause other timers to hang.
|
|
|
|
//
|
|
|
|
// This test has to be in internal_test.go since it fiddles with
|
|
|
|
// unexported data structures.
|
2015-01-15 01:27:56 +01:00
|
|
|
func CheckRuntimeTimerOverflow() {
|
2013-11-06 20:49:01 +01:00
|
|
|
// We manually create a runtimeTimer to bypass the overflow
|
|
|
|
// detection logic in NewTimer: we're testing the underlying
|
|
|
|
// runtime.addtimer function.
|
|
|
|
r := &runtimeTimer{
|
2014-07-19 10:53:52 +02:00
|
|
|
when: runtimeNano() + (1<<63 - 1),
|
2013-11-06 20:49:01 +01:00
|
|
|
f: empty,
|
|
|
|
arg: nil,
|
|
|
|
}
|
|
|
|
startTimer(r)
|
|
|
|
|
2015-01-15 01:27:56 +01:00
|
|
|
// Start a goroutine that should send on t.C right away.
|
2013-11-06 20:49:01 +01:00
|
|
|
t := NewTimer(1)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
// Subsequent tests won't work correctly if we don't stop the
|
|
|
|
// overflow timer and kick the timer proc back into service.
|
|
|
|
//
|
|
|
|
// The timer proc is now sleeping and can only be awoken by
|
|
|
|
// adding a timer to the *beginning* of the heap. We can't
|
|
|
|
// wake it up by calling NewTimer since other tests may have
|
|
|
|
// left timers running that should have expired before ours.
|
|
|
|
// Instead we zero the overflow timer duration and start it
|
|
|
|
// once more.
|
|
|
|
stopTimer(r)
|
|
|
|
t.Stop()
|
2020-01-03 00:05:27 +01:00
|
|
|
resetTimer(r, 0)
|
2013-11-06 20:49:01 +01:00
|
|
|
}()
|
|
|
|
|
2020-07-28 07:27:54 +02:00
|
|
|
// If the test fails, we will hang here until the timeout in the
|
|
|
|
// testing package fires, which is 10 minutes. It would be nice to
|
|
|
|
// catch the problem sooner, but there is no reliable way to guarantee
|
|
|
|
// that timers are run without doing something involving the scheduler.
|
|
|
|
// Previous failed attempts have tried calling runtime.Gosched and
|
|
|
|
// runtime.GC, but neither is reliable. So we fall back to hope:
|
|
|
|
// We hope we don't hang here.
|
2015-01-15 01:27:56 +01:00
|
|
|
<-t.C
|
2013-11-06 20:49:01 +01:00
|
|
|
}
|
2018-09-24 23:46:21 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
MinMonoTime = Time{wall: 1 << 63, ext: -1 << 63, loc: UTC}
|
|
|
|
MaxMonoTime = Time{wall: 1 << 63, ext: 1<<63 - 1, loc: UTC}
|
|
|
|
)
|