| 259 | } |
| 260 | |
| 261 | func TestResetChannelClear(t *testing.T) { |
| 262 | timer := NewTimer(0) |
| 263 | time.Sleep(time.Second) |
| 264 | |
| 265 | if len(timer.C) != 1 { |
| 266 | t.Errorf("reset timer: channel should be filled") |
| 267 | } |
| 268 | |
| 269 | wasActive := timer.Reset(2 * time.Second) |
| 270 | if wasActive { |
| 271 | t.Errorf("reset timer: was active is true") |
| 272 | } |
| 273 | |
| 274 | if len(timer.C) != 0 { |
| 275 | t.Errorf("reset timer: channel should be empty") |
| 276 | } |
| 277 | |
| 278 | start := time.Now() |
| 279 | <-timer.C |
| 280 | |
| 281 | if int(time.Since(start).Seconds()) != 2 { |
| 282 | t.Errorf("took ~%v seconds, should be ~2 seconds\n", int(time.Since(start).Seconds())) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func TestResetPanic(t *testing.T) { |
| 287 | defer func() { |