| 296 | } |
| 297 | |
| 298 | func TestResetBehavior(t *testing.T) { |
| 299 | start := time.Now() |
| 300 | |
| 301 | // Start a new timer with a timeout of 1 second. |
| 302 | timer := NewTimer(1 * time.Second) |
| 303 | |
| 304 | // Wait for 2 seconds. |
| 305 | // Meanwhile the timer fired filled the channel. |
| 306 | time.Sleep(2 * time.Second) |
| 307 | |
| 308 | // Reset the timer. This should act exactly as creating a new timer. |
| 309 | timer.Reset(1 * time.Second) |
| 310 | |
| 311 | // However this will fire immediately, because the channel was not drained. |
| 312 | // See issue: https://github.com/golang/go/issues/11513 |
| 313 | <-timer.C |
| 314 | |
| 315 | if int(time.Since(start).Seconds()) != 3 { |
| 316 | t.Errorf("took ~%v seconds, should be ~3 seconds\n", int(time.Since(start).Seconds())) |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | func TestMultipleTimersForValidTimeouts(t *testing.T) { |
| 321 | var wg sync.WaitGroup |