(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestTimerPool(t *testing.T) { |
| 22 | var tp timerPool |
| 23 | |
| 24 | for i := 0; i < 10; i++ { |
| 25 | tm := tp.Get(time.Millisecond * 20) |
| 26 | |
| 27 | select { |
| 28 | case <-tm.C: |
| 29 | t.Errorf("Timer already expired") |
| 30 | continue |
| 31 | default: |
| 32 | } |
| 33 | |
| 34 | select { |
| 35 | case <-tm.C: |
| 36 | case <-time.After(time.Millisecond * 100): |
| 37 | t.Errorf("Timer didn't expire in time") |
| 38 | } |
| 39 | |
| 40 | tp.Put(tm) |
| 41 | } |
| 42 | } |