Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Issue 2484023002: Use a TickClock instead of TimeTicks::Now() in Timer. (Closed)

Created:
4 years, 1 month ago by jameswest
Modified:
4 years, 1 month ago
CC:
chromium-reviews, chirantan+watch_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Use a TickClock instead of TimeTicks::Now() in Timer. Code that uses a Timer cannot be unit tested without using sleep or a mock timer because Timer uses TimeTicks::Now() to calculate the run time for scheduled tasks. Using sleep makes tests slow and unreliable, and using mock timers frequently requires unit tests to have knowledge of internal implementation details of the code being tested. By using a TickClock, tests can provide a mock implementation of the TickClock that can be advanced without the use of sleep, allowing tests to reliably verify the behavior of code as time advances. BUG=internal b/32644077 Committed: https://crrev.com/6e0c8d22b864d84946417eb6379c1513c36d48b0 Cr-Commit-Position: refs/heads/master@{#432113}

Patch Set 1 #

Total comments: 2

Patch Set 2 : Pass TickClock pointer to Timer constructor. #

Patch Set 3 : Fix error. #

Patch Set 4 : Added unit tests and removed Chrome OS changes. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+135 lines, -18 lines) Patch
M base/timer/timer.h View 1 8 chunks +38 lines, -7 lines 0 comments Download
M base/timer/timer.cc View 1 6 chunks +29 lines, -11 lines 0 comments Download
M base/timer/timer_unittest.cc View 1 2 3 5 chunks +68 lines, -0 lines 0 comments Download

Messages

Total messages: 26 (8 generated)
jameswest
4 years, 1 month ago (2016-11-07 23:19:34 UTC) #3
Avi (use Gerrit)
Yes, this is cool, but my OK doesn't matter here so I'll wander off.
4 years, 1 month ago (2016-11-08 16:25:35 UTC) #5
Avi (use Gerrit)
On 2016/11/08 16:25:35, Avi wrote: > Yes, this is cool, but my OK doesn't matter ...
4 years, 1 month ago (2016-11-08 16:27:24 UTC) #6
danakj
https://codereview.chromium.org/2484023002/diff/1/base/timer/timer.h File base/timer/timer.h (right): https://codereview.chromium.org/2484023002/diff/1/base/timer/timer.h#newcode100 base/timer/timer.h:100: virtual void SetTickClock(std::unique_ptr<TickClock> tick_clock); This class being virtual means ...
4 years, 1 month ago (2016-11-09 19:57:38 UTC) #7
jameswest
https://codereview.chromium.org/2484023002/diff/1/base/timer/timer.h File base/timer/timer.h (right): https://codereview.chromium.org/2484023002/diff/1/base/timer/timer.h#newcode100 base/timer/timer.h:100: virtual void SetTickClock(std::unique_ptr<TickClock> tick_clock); On 2016/11/09 19:57:38, danakj wrote: ...
4 years, 1 month ago (2016-11-10 00:26:05 UTC) #8
danakj
On Wed, Nov 9, 2016 at 4:26 PM, <jameswest@google.com> wrote: > > https://codereview.chromium.org/2484023002/diff/1/base/timer/timer.h > File ...
4 years, 1 month ago (2016-11-10 01:31:27 UTC) #9
jameswest
> Ah, right that's not so good. I was thinking in terms of forcing subclasses ...
4 years, 1 month ago (2016-11-10 02:20:52 UTC) #10
jameswest
On 2016/11/10 02:20:52, jameswest wrote: > > Ah, right that's not so good. I was ...
4 years, 1 month ago (2016-11-10 02:52:34 UTC) #11
jameswest
On 2016/11/10 02:52:34, jameswest wrote: > On 2016/11/10 02:20:52, jameswest wrote: > > > Ah, ...
4 years, 1 month ago (2016-11-10 03:06:11 UTC) #12
danakj
On Wed, Nov 9, 2016 at 7:06 PM, <jameswest@google.com> wrote: > On 2016/11/10 02:52:34, jameswest ...
4 years, 1 month ago (2016-11-12 00:42:59 UTC) #13
jameswest
On 2016/11/12 00:42:59, danakj wrote: > On Wed, Nov 9, 2016 at 7:06 PM, <mailto:jameswest@google.com> ...
4 years, 1 month ago (2016-11-15 00:55:58 UTC) #14
danakj
LGTM. You /could/ leave the chromeos timer out if u want now too since it ...
4 years, 1 month ago (2016-11-15 01:05:33 UTC) #16
danakj
On Mon, Nov 14, 2016 at 5:05 PM, <danakj@chromium.org> wrote: > LGTM. > > You ...
4 years, 1 month ago (2016-11-15 01:06:44 UTC) #17
jameswest
On 2016/11/15 01:06:44, danakj wrote: > On Mon, Nov 14, 2016 at 5:05 PM, <mailto:danakj@chromium.org> ...
4 years, 1 month ago (2016-11-15 02:46:38 UTC) #18
danakj
Thanks for the tests! They LGTM
4 years, 1 month ago (2016-11-15 02:50:00 UTC) #21
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2484023002/60001
4 years, 1 month ago (2016-11-15 02:50:38 UTC) #22
commit-bot: I haz the power
Committed patchset #4 (id:60001)
4 years, 1 month ago (2016-11-15 05:20:27 UTC) #24
commit-bot: I haz the power
4 years, 1 month ago (2016-11-15 05:22:53 UTC) #26
Message was sent while issue was closed.
Patchset 4 (id:??) landed as
https://crrev.com/6e0c8d22b864d84946417eb6379c1513c36d48b0
Cr-Commit-Position: refs/heads/master@{#432113}

Powered by Google App Engine
This is Rietveld 408576698