Source file src/time/internal_test.go

     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  	// For hermeticity, use only tzinfo source from the test's GOROOT,
    14  	// not the system sources and not whatever GOROOT may happen to be
    15  	// set in the process's environment (if any).
    16  	// This test runs in GOROOT/src/time, so GOROOT is "../..",
    17  	// but it is theoretically possible
    18  	sources := []string{"../../lib/time/zoneinfo.zip"}
    19  	z, err := loadLocation("America/Los_Angeles", sources)
    20  	if err != nil {
    21  		panic("cannot load America/Los_Angeles for testing: " + err.Error() + "; you may want to use -tags=timetzdata")
    22  	}
    23  	z.name = "Local"
    24  	localLoc = *z
    25  }
    26  
    27  var origPlatformZoneSources []string = platformZoneSources
    28  
    29  func disablePlatformSources() (undo func()) {
    30  	platformZoneSources = nil
    31  	return func() {
    32  		platformZoneSources = origPlatformZoneSources
    33  	}
    34  }
    35  
    36  var Interrupt = interrupt
    37  var DaysIn = daysIn
    38  
    39  func empty(arg any, seq uintptr, delta int64) {}
    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  	t := newTimer(runtimeNano(), 1<<63-1, empty, nil, nil)
    51  	defer t.Stop()
    52  
    53  	// If this test fails, we will either throw (when siftdownTimer detects
    54  	// bad when on update), or other timers will hang (if the timer in a
    55  	// heap is in a bad state). There is no reliable way to test this, but
    56  	// we wait on a short timer here as a smoke test (alternatively, timers
    57  	// in later tests may hang).
    58  	<-After(25 * Millisecond)
    59  }
    60  
    61  var (
    62  	MinMonoTime = Time{wall: 1 << 63, ext: -1 << 63, loc: UTC}
    63  	MaxMonoTime = Time{wall: 1 << 63, ext: 1<<63 - 1, loc: UTC}
    64  
    65  	NotMonoNegativeTime = Time{wall: 0, ext: -1<<63 + 50}
    66  )
    67  

View as plain text