s***@chromium.org
2018-11-15 01:27:43 UTC
I recently wrote a unittest that used Time::Now() and it started failing
the day after daylights savings time <https://crbug.com/901698>. It assumed
the current day would have 24 hours, which in retrospect is clearly not
safe. But at the time, I didn't even consider the possibility.
It seems to me like putting Time::Now() in tests is dangerous and should be
stopped by a global PRESUBMIT. The disadvantages of Time::Now() that I see
in tests are:
- Each test run is slightly different.
- Daylight Savings Time can cause temporary failures.
- Leap Year can cause temporary failures.
If you want your tests and impl to agree on the time, they should be
sharing a base::Clock. Or, seemingly more often, use base::TimeTicks
instead of base::Time.
There's been a thread (Testing base::OneShotTimer / "waiting" in a browser
test
<https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GyyJOmWGSVk>)
and a bug <https://bugs.chromium.org/p/chromium/issues/detail?id=905412> about
process wide mocking of base::TimeTicks. But I don't this changes not
wanting Time::Now() in tests. And it doesn't sound like
<https://chromium-review.googlesource.com/c/chromium/src/+/1324414> there
are plans to process wide mock base::Time::Now().
Does anyone have concerns about this?
Thanks,
Sky
the day after daylights savings time <https://crbug.com/901698>. It assumed
the current day would have 24 hours, which in retrospect is clearly not
safe. But at the time, I didn't even consider the possibility.
It seems to me like putting Time::Now() in tests is dangerous and should be
stopped by a global PRESUBMIT. The disadvantages of Time::Now() that I see
in tests are:
- Each test run is slightly different.
- Daylight Savings Time can cause temporary failures.
- Leap Year can cause temporary failures.
If you want your tests and impl to agree on the time, they should be
sharing a base::Clock. Or, seemingly more often, use base::TimeTicks
instead of base::Time.
There's been a thread (Testing base::OneShotTimer / "waiting" in a browser
test
<https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GyyJOmWGSVk>)
and a bug <https://bugs.chromium.org/p/chromium/issues/detail?id=905412> about
process wide mocking of base::TimeTicks. But I don't this changes not
wanting Time::Now() in tests. And it doesn't sound like
<https://chromium-review.googlesource.com/c/chromium/src/+/1324414> there
are plans to process wide mock base::Time::Now().
Does anyone have concerns about this?
Thanks,
Sky
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e78d75b2-7511-4605-bdaf-122214fac38e%40chromium.org.
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e78d75b2-7511-4605-bdaf-122214fac38e%40chromium.org.