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