1 // Copyright 2009 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.
12 func TestTicker(t
*testing
.T
) {
17 ticker
:= NewTicker(Delta
)
19 for i
:= 0; i
< Count
; i
++ {
25 target
:= int64(Delta
* Count
)
26 slop
:= target
* 2 / 10
27 if ns
< target
-slop || ns
> target
+slop
{
28 t
.Fatalf("%d ticks of %g ns took %g ns, expected %g", Count
, float64(Delta
), float64(ns
), float64(target
))
30 // Now test that the ticker stopped
32 _
, received
:= <-ticker
.C
34 t
.Fatalf("Ticker did not shut down")
38 // Test that a bug tearing down a ticker has been fixed. This routine should not deadlock.
39 func TestTeardown(t
*testing
.T
) {
40 for i
:= 0; i
< 3; i
++ {
41 ticker
:= NewTicker(1e8
)