Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 1 | package ipc |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func 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 | } |