| 172 | } |
| 173 | |
| 174 | func TestReset(t *testing.T) { |
| 175 | start := time.Now() |
| 176 | timer := NewTimer(time.Second) |
| 177 | wasActive := timer.Reset(2 * time.Second) |
| 178 | if !wasActive { |
| 179 | t.Errorf("reset timer: was active is false") |
| 180 | } |
| 181 | |
| 182 | <-timer.C |
| 183 | |
| 184 | if int(time.Since(start).Seconds()) != 2 { |
| 185 | t.Errorf("took ~%v seconds, should be ~2 seconds\n", int(time.Since(start).Seconds())) |
| 186 | } |
| 187 | |
| 188 | start = time.Now() |
| 189 | wasActive = timer.Reset(time.Second) |
| 190 | if wasActive { |
| 191 | t.Errorf("reset timer: was active is true") |
| 192 | } |
| 193 | |
| 194 | <-timer.C |
| 195 | |
| 196 | if int(time.Since(start).Seconds()) != 1 { |
| 197 | t.Errorf("took ~%v seconds, should be ~1 seconds\n", int(time.Since(start).Seconds())) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func TestNegativeReset(t *testing.T) { |
| 202 | // Timeout for -1 seconds. |