* gcc.dg/ipa/inlinehint-4.c: Also pass --param inline-unit-growth=20.
[official-gcc.git] / libgo / go / time / tick_test.go
blobdd17aab1b15364d53f91d25693938669156bf605
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.
5 package time_test
7 import (
8 "testing"
9 . "time"
12 func TestTicker(t *testing.T) {
13 const Count = 10
14 Delta := 100 * Millisecond
15 ticker := NewTicker(Delta)
16 t0 := Now()
17 for i := 0; i < Count; i++ {
18 <-ticker.C
20 ticker.Stop()
21 t1 := Now()
22 dt := t1.Sub(t0)
23 target := Delta * Count
24 slop := target * 2 / 10
25 if dt < target-slop || (!testing.Short() && dt > target+slop) {
26 t.Fatalf("%d %s ticks took %s, expected [%s,%s]", Count, Delta, dt, target-slop, target+slop)
28 // Now test that the ticker stopped
29 Sleep(2 * Delta)
30 select {
31 case <-ticker.C:
32 t.Fatal("Ticker did not shut down")
33 default:
34 // ok
38 // Issue 21874
39 func TestTickerStopWithDirectInitialization(t *testing.T) {
40 c := make(chan Time)
41 tk := &Ticker{C: c}
42 tk.Stop()
45 // Test that a bug tearing down a ticker has been fixed. This routine should not deadlock.
46 func TestTeardown(t *testing.T) {
47 Delta := 100 * Millisecond
48 if testing.Short() {
49 Delta = 20 * Millisecond
51 for i := 0; i < 3; i++ {
52 ticker := NewTicker(Delta)
53 <-ticker.C
54 ticker.Stop()
58 // Test the Tick convenience wrapper.
59 func TestTick(t *testing.T) {
60 // Test that giving a negative duration returns nil.
61 if got := Tick(-1); got != nil {
62 t.Errorf("Tick(-1) = %v; want nil", got)
66 // Test that NewTicker panics when given a duration less than zero.
67 func TestNewTickerLtZeroDuration(t *testing.T) {
68 defer func() {
69 if err := recover(); err == nil {
70 t.Errorf("NewTicker(-1) should have panicked")
72 }()
73 NewTicker(-1)
76 func BenchmarkTicker(b *testing.B) {
77 benchmark(b, func(n int) {
78 ticker := NewTicker(Nanosecond)
79 for i := 0; i < n; i++ {
80 <-ticker.C
82 ticker.Stop()