| 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 |
import "runtime" |
| 8 |
|
| 9 |
func init() { |
| 10 |
// force US/Pacific for time zone tests |
| 11 |
ForceUSPacificForTesting() |
| 12 |
} |
| 13 |
|
| 14 |
func initTestingZone() { |
| 15 |
z, err := loadLocation("America/Los_Angeles", zoneSources[len(zoneSources)-1:]) |
| 16 |
if runtime.Compiler == "gccgo" && err != nil { |
| 17 |
z, err = loadLocation("America/Los_Angeles", zoneSources) |
| 18 |
} |
| 19 |
if err != nil { |
| 20 |
panic("cannot load America/Los_Angeles for testing: " + err.Error() + "; you may want to use -tags=timetzdata") |
| 21 |
} |
| 22 |
z.name = "Local" |
| 23 |
localLoc = *z |
| 24 |
} |
| 25 |
|
| 26 |
var OrigZoneSources = zoneSources |
| 27 |
|
| 28 |
func forceZipFileForTesting(zipOnly bool) { |
| 29 |
zoneSources = make([]string, len(OrigZoneSources)) |
| 30 |
copy(zoneSources, OrigZoneSources) |
| 31 |
if zipOnly { |
| 32 |
zoneSources = zoneSources[len(zoneSources)-1:] |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
var Interrupt = interrupt |
| 37 |
var DaysIn = daysIn |
| 38 |
|
| 39 |
func empty(arg any, seq uintptr) {} |
| 40 |
|
| 41 |
// Test that a runtimeTimer with a period that would overflow when on |
| 42 |
// expiration does not throw or cause other timers to hang. |
| 43 |
// |
| 44 |
// This test has to be in internal_test.go since it fiddles with |
| 45 |
// unexported data structures. |
| 46 |
func CheckRuntimeTimerPeriodOverflow() { |
| 47 |
// We manually create a runtimeTimer with huge period, but that expires |
| 48 |
// immediately. The public Timer interface would require waiting for |
| 49 |
// the entire period before the first update. |
| 50 |
r := &runtimeTimer{ |
| 51 |
when: runtimeNano(), |
| 52 |
period: 1<<63 - 1, |
| 53 |
f: empty, |
| 54 |
arg: nil, |
| 55 |
} |
| 56 |
startTimer(r) |
| 57 |
defer stopTimer(r) |
| 58 |
|
| 59 |
// If this test fails, we will either throw (when siftdownTimer detects |
| 60 |
// bad when on update), or other timers will hang (if the timer in a |
| 61 |
// heap is in a bad state). There is no reliable way to test this, but |
| 62 |
// we wait on a short timer here as a smoke test (alternatively, timers |
| 63 |
// in later tests may hang). |
| 64 |
<-After(25 * Millisecond) |
| 65 |
} |
| 66 |
|
| 67 |
var ( |
| 68 |
MinMonoTime = Time{wall: 1 << 63, ext: -1 << 63, loc: UTC} |
| 69 |
MaxMonoTime = Time{wall: 1 << 63, ext: 1<<63 - 1, loc: UTC} |
| 70 |
|
| 71 |
NotMonoNegativeTime = Time{wall: 0, ext: -1<<63 + 50} |
| 72 |
) |