blob: e7345d6dfcabc1bfc835685d905c0ca114286162 [file] [log] [blame]
Matt Rosencrantz86897932014-10-02 09:34:34 -07001package ipc
2
3import (
4 "testing"
5 "time"
6)
7
8func TestTimer(t *testing.T) {
9 test := newTimer(time.Millisecond)
10 if _, ok := <-test.C; ok {
11 t.Errorf("Expected the channel to be closed.")
12 }
13
14 // Test resetting.
15 test = newTimer(time.Hour)
16 if reset := test.Reset(time.Millisecond); !reset {
17 t.Errorf("Expected to successfully reset.")
18 }
19 if _, ok := <-test.C; ok {
20 t.Errorf("Expected the channel to be closed.")
21 }
22
23 // Test stop.
24 test = newTimer(100 * time.Millisecond)
25 test.Stop()
26 select {
27 case <-test.C:
28 t.Errorf("the test timer should have been stopped.")
29 case <-time.After(200 * time.Millisecond):
30 }
31}