2011-08-26 15:15:23 -04: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
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
// force US/Pacific for time zone tests
|
2013-01-14 14:09:42 -08:00
|
|
|
ForceUSPacificForTesting()
|
2011-08-26 15:15:23 -04:00
|
|
|
}
|
|
|
|
|
|
2017-09-18 19:22:29 +02:00
|
|
|
func initTestingZone() {
|
|
|
|
|
z, err := loadLocation("America/Los_Angeles", zoneSources[len(zoneSources)-1:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic("cannot load America/Los_Angeles for testing: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
z.name = "Local"
|
|
|
|
|
localLoc = *z
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 17:16:43 +02:00
|
|
|
var OrigZoneSources = zoneSources
|
2017-09-18 19:22:29 +02:00
|
|
|
|
|
|
|
|
func forceZipFileForTesting(zipOnly bool) {
|
2017-10-06 17:16:43 +02:00
|
|
|
zoneSources = make([]string, len(OrigZoneSources))
|
|
|
|
|
copy(zoneSources, OrigZoneSources)
|
2017-09-18 19:22:29 +02:00
|
|
|
if zipOnly {
|
|
|
|
|
zoneSources = zoneSources[len(zoneSources)-1:]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 15:15:23 -04:00
|
|
|
var Interrupt = interrupt
|
2011-12-07 14:47:25 -05:00
|
|
|
var DaysIn = daysIn
|
2013-09-06 15:47:39 -04:00
|
|
|
|
2014-09-04 10:04:04 +04:00
|
|
|
func empty(arg interface{}, seq uintptr) {}
|
2013-09-06 15:47:39 -04: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.
|
2014-06-12 11:44:55 -07:00
|
|
|
func CheckRuntimeTimerOverflow() {
|
2013-09-06 15:47:39 -04:00
|
|
|
// We manually create a runtimeTimer to bypass the overflow
|
|
|
|
|
// detection logic in NewTimer: we're testing the underlying
|
|
|
|
|
// runtime.addtimer function.
|
|
|
|
|
r := &runtimeTimer{
|
runtime: use monotonic clock for timers (linux/386, linux/amd64)
This lays the groundwork for making Go robust when the system's
calendar time jumps around. All input values to the runtimeTimer
struct now use the runtime clock as a common reference point.
This affects net.Conn.Set[Read|Write]Deadline(), time.Sleep(),
time.Timer, etc. Under normal conditions, behavior is unchanged.
Each platform and architecture's implementation of runtime·nanotime()
should be modified to use a monotonic system clock when possible.
Platforms/architectures modified and tested with monotonic clock:
linux/x86 - clock_gettime(CLOCK_MONOTONIC)
Update #6007
LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, alex.brainman, stephen.gutekanst, dave, rsc, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/53010043
2014-02-24 10:57:46 -05:00
|
|
|
when: runtimeNano() + (1<<63 - 1),
|
2013-09-06 15:47:39 -04:00
|
|
|
f: empty,
|
|
|
|
|
arg: nil,
|
|
|
|
|
}
|
|
|
|
|
startTimer(r)
|
|
|
|
|
|
2014-06-12 11:44:55 -07:00
|
|
|
// Start a goroutine that should send on t.C right away.
|
2013-09-06 15:47:39 -04:00
|
|
|
t := NewTimer(1)
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
stopTimer(r)
|
|
|
|
|
t.Stop()
|
|
|
|
|
}()
|
|
|
|
|
|
2020-03-10 22:11:00 -07: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.
|
2014-06-12 11:44:55 -07:00
|
|
|
<-t.C
|
2013-09-06 15:47:39 -04:00
|
|
|
}
|
2018-04-14 10:50:52 +03:00
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
MinMonoTime = Time{wall: 1 << 63, ext: -1 << 63, loc: UTC}
|
|
|
|
|
MaxMonoTime = Time{wall: 1 << 63, ext: 1<<63 - 1, loc: UTC}
|
|
|
|
|
)
|