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.
13 // force US/Pacific for time zone tests
14 ForceUSPacificForTesting()
17 var Interrupt
= interrupt
20 func empty(now
int64, arg
interface{}) {}
22 // Test that a runtimeTimer with a duration so large it overflows
23 // does not cause other timers to hang.
25 // This test has to be in internal_test.go since it fiddles with
26 // unexported data structures.
27 func CheckRuntimeTimerOverflow() error
{
28 // We manually create a runtimeTimer to bypass the overflow
29 // detection logic in NewTimer: we're testing the underlying
30 // runtime.addtimer function.
32 when
: nano() + (1<<63 - 1),
38 timeout
:= 100 * Millisecond
39 if runtime
.GOOS
== "windows" {
40 // Allow more time for gobuilder to succeed.
44 // Start a goroutine that should send on t.C before the timeout.
48 // Subsequent tests won't work correctly if we don't stop the
49 // overflow timer and kick the timer proc back into service.
51 // The timer proc is now sleeping and can only be awoken by
52 // adding a timer to the *beginning* of the heap. We can't
53 // wake it up by calling NewTimer since other tests may have
54 // left timers running that should have expired before ours.
55 // Instead we zero the overflow timer duration and start it
63 // Try to receive from t.C before the timeout. It will succeed
64 // iff the previous sleep was able to finish. We're forced to
65 // spin and yield after trying to receive since we can't start
66 // any more timers (they might hang due to the same bug we're
68 stop
:= Now().Add(timeout
)
72 return nil // It worked!
74 if Now().After(stop
) {
75 return errors
.New("runtime timer stuck: overflow in addtimer")