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

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)

Created:
3 years, 11 months ago by gab
Modified:
3 years, 9 months ago
CC:
chromium-reviews, vmpstr+watch_chromium.org, bruthig
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. Will be used to provide proper ThreadTaskRunnerHandle context in unit tests when multiple test task runners share the main thread. TestMockTimeTaskRunner::ScopedContext as discussed @ https://groups.google.com/a/chromium.org/d/msg/chromium-dev/kSIe9p5ZYGM/koFefJmNCAAJ This cleans up HttpServerPropertiesManagerTest to actually run code in the scope of the task runners the impl expects it to (it would previously pass because TestMockTimeTaskRunner::RunsOnCurrentThread() is looser than it should be -- merely checks thread id, not runner context). This is a prerequisite for https://codereview.chromium.org/2491613004/ as it otherwise breaks per its tasks posting to unexpected tasks runners (i.e. the current ThreadTaskRunnerHandle() which was the underlying unmocked MessageLoop in these tests). Further addressed in those tests: - No longer need to use MessageLoop/RunLoop - Which removes need for completion Closure on the updates. - Exposes timer timings to fast-forward by the right timing instead of FastForwardUntilNoTasksRemain() -- test could use some more cleanup in that regard but that's a first pass of mandatory sites. Also addressed in this CL: - ServerBackedStateKeysBrokerTest.Refresh, RecentTabHelperTest, AffiliatedMatchHelperTest, and SyncStoppedReporterTest - Now mocks main thread runner directly, removes need for test-only SetTaskRunner() methods :). (having a custom TaskRunner was causing things like observers to post to the wrong task runner per this CL's ThreadTaskRunnerHandle override in its deferred initialization). - AsyncDocumentSubresourceFilterTest, WallPaperColorCalculatorTest and PostAndReplyImplTest - Unfortunately those tests were fine but as documented in thread_task_runner_handle.cc: supporting SequencedTaskRunnerHandle overrides from main thread would be overkill for now... so they were tweaked to avoid doing that. - Also, upcoming base::test::ScopedTaskEnvironment makes all of this an implementation detail anyways: draft @ https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3Pkk/edit BUG=587199 Review-Url: https://codereview.chromium.org/2657013002 Cr-Commit-Position: refs/heads/master@{#454127} Committed: https://chromium.googlesource.com/chromium/src/+/a6f723282862820eed7df3a375a3f922996d846e

Patch Set 1 : WIP #

Patch Set 2 : net_unittests works #

Total comments: 1

Patch Set 3 : nvm : still need the completion closure e.g. profile_impl_io_data.cc -> Clear() #

Total comments: 15

Patch Set 4 : fix task runner paradigms in SyncStoppedReporterTest and ServerBackedStateKeysBrokerTest #

Total comments: 12

Patch Set 5 : review:xunjeli#33 #

Total comments: 2

Patch Set 6 : ThreadTaskRunnerHandle::OverrideForTesting #

Patch Set 7 : better dcheck comment #

Patch Set 8 : rebase on r451301 #

Patch Set 9 : rebase on r453103 #

Patch Set 10 : fix AffiliatedMatchHelperTest* AsyncDocumentSubResourceFilterTest* and PostTaskAndReplyImpl's test #

Total comments: 2

Patch Set 11 : STRH->TTRH in WallPaperColorCalculatorTest :( #

Patch Set 12 : review:fdoray #

Patch Set 13 : Fix and further cleanup of ServerBackedStateKeysBrokerTest #

Patch Set 14 : Fix and cleanup RecentTabHelperTest #

Patch Set 15 : fix compile #

Patch Set 16 : fix include #

Patch Set 17 : fix RecentTabHelperTest #

Patch Set 18 : fix ServerBackedStateKeysBrokerTest fast-forward logic #

Patch Set 19 : fix RecentTabHelperTest crash? #

Total comments: 8
Unified diffs Side-by-side diffs Delta from patch set Stats (+588 lines, -317 lines) Patch
M base/BUILD.gn View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M base/test/test_mock_time_task_runner.h View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +48 lines, -0 lines 0 comments Download
M base/test/test_mock_time_task_runner.cc View 1 2 3 4 5 4 chunks +23 lines, -0 lines 0 comments Download
M base/test/test_simple_task_runner.cc View 1 2 3 4 5 3 chunks +13 lines, -0 lines 0 comments Download
M base/threading/post_task_and_reply_impl_unittest.cc View 1 2 3 4 5 6 7 8 9 2 chunks +2 lines, -2 lines 0 comments Download
M base/threading/thread_task_runner_handle.h View 1 2 3 4 5 2 chunks +12 lines, -0 lines 0 comments Download
M base/threading/thread_task_runner_handle.cc View 1 2 3 4 5 6 7 8 9 2 chunks +46 lines, -0 lines 0 comments Download
A base/threading/thread_task_runner_handle_unittest.cc View 1 2 3 4 5 1 chunk +122 lines, -0 lines 0 comments Download
M chrome/browser/android/offline_pages/recent_tab_helper.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +0 lines, -1 line 0 comments Download
M chrome/browser/android/offline_pages/recent_tab_helper.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 2 chunks +1 line, -4 lines 0 comments Download
M chrome/browser/android/offline_pages/recent_tab_helper_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 25 chunks +28 lines, -38 lines 0 comments Download
M chrome/browser/chromeos/policy/browser_policy_connector_chromeos.cc View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -2 lines 0 comments Download
M chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -2 lines 0 comments Download
M chrome/browser/chromeos/policy/server_backed_state_keys_broker.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 4 chunks +3 lines, -9 lines 0 comments Download
M chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 4 chunks +11 lines, -9 lines 4 comments Download
M chrome/browser/chromeos/policy/server_backed_state_keys_broker_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 10 chunks +13 lines, -14 lines 4 comments Download
M components/password_manager/core/browser/affiliated_match_helper.h View 1 2 3 4 5 6 7 8 9 3 chunks +3 lines, -8 lines 0 comments Download
M components/password_manager/core/browser/affiliated_match_helper.cc View 1 2 3 4 5 6 7 8 9 3 chunks +6 lines, -11 lines 0 comments Download
M components/password_manager/core/browser/affiliated_match_helper_unittest.cc View 1 2 3 4 5 6 7 8 9 11 chunks +26 lines, -27 lines 0 comments Download
M components/subresource_filter/content/browser/async_document_subresource_filter_unittest.cc View 1 2 3 4 5 6 7 8 9 4 chunks +11 lines, -10 lines 0 comments Download
M components/sync/driver/sync_stopped_reporter.h View 1 2 3 4 5 6 7 1 chunk +0 lines, -4 lines 0 comments Download
M components/sync/driver/sync_stopped_reporter.cc View 1 2 3 1 chunk +0 lines, -5 lines 0 comments Download
M components/sync/driver/sync_stopped_reporter_unittest.cc View 1 2 3 3 chunks +11 lines, -18 lines 0 comments Download
M components/wallpaper/wallpaper_color_calculator_unittest.cc View 1 2 3 4 5 6 7 8 9 10 4 chunks +6 lines, -5 lines 0 comments Download
M net/http/http_server_properties_manager.h View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
M net/http/http_server_properties_manager.cc View 1 2 3 4 5 6 7 8 5 chunks +17 lines, -6 lines 0 comments Download
M net/http/http_server_properties_manager_unittest.cc View 1 2 3 4 5 18 chunks +180 lines, -142 lines 0 comments Download

Messages

Total messages: 124 (94 generated)
gab
@dana for //base @zhongyi (+CC xunjieli) for //net (essentially a follow-up cleanup to https://codereview.chromium.org/2681383002 which ...
3 years, 10 months ago (2017-02-15 17:56:07 UTC) #14
gab
On 2017/02/15 17:56:07, gab wrote: > @dana for //base > @zhongyi (+CC xunjieli) for //net ...
3 years, 10 months ago (2017-02-15 21:55:41 UTC) #26
Zhongyi Shi
Thanks for clean this up! A few nits. https://codereview.chromium.org/2657013002/diff/60001/net/http/http_server_properties_manager.cc File net/http/http_server_properties_manager.cc (right): https://codereview.chromium.org/2657013002/diff/60001/net/http/http_server_properties_manager.cc#newcode371 net/http/http_server_properties_manager.cc:371: return ...
3 years, 10 months ago (2017-02-15 22:04:42 UTC) #28
Nicolas Zea
sync lgtm
3 years, 10 months ago (2017-02-15 22:08:05 UTC) #29
gab
Replies from phone, thanks https://codereview.chromium.org/2657013002/diff/60001/net/http/http_server_properties_manager.cc File net/http/http_server_properties_manager.cc (right): https://codereview.chromium.org/2657013002/diff/60001/net/http/http_server_properties_manager.cc#newcode371 net/http/http_server_properties_manager.cc:371: return kUpdateCacheDelay; On 2017/02/15 22:04:42, ...
3 years, 10 months ago (2017-02-15 22:29:16 UTC) #30
xunjieli
net/ LGTM mod nits. Thanks for addressing the todo! https://codereview.chromium.org/2657013002/diff/80001/net/http/http_server_properties_manager.cc File net/http/http_server_properties_manager.cc (right): https://codereview.chromium.org/2657013002/diff/80001/net/http/http_server_properties_manager.cc#newcode84 net/http/http_server_properties_manager.cc:84: ...
3 years, 10 months ago (2017-02-16 02:49:18 UTC) #33
emaxx
lgtm for chrome/browser/chromeos/policy/
3 years, 10 months ago (2017-02-16 03:07:38 UTC) #34
gab
Nits addressed, thanks. @dana for //base, as discussed in email thread. https://codereview.chromium.org/2657013002/diff/80001/net/http/http_server_properties_manager.cc File net/http/http_server_properties_manager.cc (right): ...
3 years, 10 months ago (2017-02-16 16:50:17 UTC) #35
xunjieli
https://codereview.chromium.org/2657013002/diff/80001/net/http/http_server_properties_manager.cc File net/http/http_server_properties_manager.cc (right): https://codereview.chromium.org/2657013002/diff/80001/net/http/http_server_properties_manager.cc#newcode84 net/http/http_server_properties_manager.cc:84: DCHECK(pref_delegate_); On 2017/02/16 16:50:15, gab wrote: > On 2017/02/16 ...
3 years, 10 months ago (2017-02-16 17:08:30 UTC) #38
danakj
https://codereview.chromium.org/2657013002/diff/60001/base/test/test_mock_time_task_runner.cc File base/test/test_mock_time_task_runner.cc (right): https://codereview.chromium.org/2657013002/diff/60001/base/test/test_mock_time_task_runner.cc#newcode127 base/test/test_mock_time_task_runner.cc:127: : task_runner_handle_(scope) { move() https://codereview.chromium.org/2657013002/diff/60001/base/test/test_mock_time_task_runner.cc#newcode128 base/test/test_mock_time_task_runner.cc:128: scope->RunUntilIdle(); then task_runner_handle_-> ...
3 years, 10 months ago (2017-02-16 17:57:24 UTC) #41
Zhongyi Shi
Thanks for doing this! Most of the net changes look good to me, I'll come ...
3 years, 10 months ago (2017-02-16 19:35:25 UTC) #42
gab
Thanks, found an even cleaner alternative :) https://codereview.chromium.org/2657013002/diff/60001/base/test/test_mock_time_task_runner.cc File base/test/test_mock_time_task_runner.cc (right): https://codereview.chromium.org/2657013002/diff/60001/base/test/test_mock_time_task_runner.cc#newcode127 base/test/test_mock_time_task_runner.cc:127: : task_runner_handle_(scope) ...
3 years, 10 months ago (2017-02-16 21:03:37 UTC) #44
gab
On 2017/02/16 19:35:25, Zhongyi Shi wrote: > Thanks for doing this! > > Most of ...
3 years, 10 months ago (2017-02-16 21:44:05 UTC) #48
Zhongyi Shi
lgtm!
3 years, 10 months ago (2017-02-16 21:59:07 UTC) #49
danakj
Thanks for the tests too, LGTM
3 years, 10 months ago (2017-02-16 22:38:25 UTC) #52
danakj
The CL desc needs to be updated for the new approach
3 years, 10 months ago (2017-02-16 22:38:44 UTC) #53
gab
On 2017/02/16 22:38:44, danakj wrote: > The CL desc needs to be updated for the ...
3 years, 10 months ago (2017-02-17 14:16:11 UTC) #55
gab
@engedy for test tweaks in components/password_manager/* and components/subresource_filter/* @fdoray to double-check diff between PS 8 ...
3 years, 9 months ago (2017-02-27 20:56:30 UTC) #68
fdoray
lgtm https://codereview.chromium.org/2657013002/diff/220001/base/test/test_mock_time_task_runner.h File base/test/test_mock_time_task_runner.h (right): https://codereview.chromium.org/2657013002/diff/220001/base/test/test_mock_time_task_runner.h#newcode77 base/test/test_mock_time_task_runner.h:77: // TestMockTimeTaskRunner::ScopedContext(foo_task_runner_.get()); add variable name
3 years, 9 months ago (2017-02-28 04:11:21 UTC) #73
gab
+bshe@ for components/wallpaper/* tweaks (CC bruthig per https://codereview.chromium.org/2679133003) ping engedy@ for test tweaks in components/password_manager/* ...
3 years, 9 months ago (2017-02-28 19:16:03 UTC) #76
engedy
LGTM on components/password_manager/ and components/subresource_filter/.
3 years, 9 months ago (2017-02-28 21:30:07 UTC) #81
bshe
On 2017/02/28 21:30:07, engedy (slow) wrote: > LGTM on components/password_manager/ and components/subresource_filter/. wallpaper lgtm
3 years, 9 months ago (2017-02-28 21:55:20 UTC) #82
gab
@emaxx: further cleanup of chromeos/policy/ :) PTanL @petewil for chrome/browser/android/offline_pages/ tweaks Thanks! Gab
3 years, 9 months ago (2017-03-01 02:28:08 UTC) #89
emaxx
LGTM with nits (sorry for not pointing out them earlier) https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc File chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc (right): https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc#newcode100 ...
3 years, 9 months ago (2017-03-01 14:43:53 UTC) #114
Pete Williamson
Offline Pages changes LGTM as long as the tests pass (and they appear to be ...
3 years, 9 months ago (2017-03-01 18:07:32 UTC) #115
gab
Thanks, @emaxx: reply to nits below. I'll CQ now but happy to discuss further if ...
3 years, 9 months ago (2017-03-02 00:33:31 UTC) #116
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/2657013002/400001
3 years, 9 months ago (2017-03-02 00:34:23 UTC) #119
commit-bot: I haz the power
Committed patchset #19 (id:400001) as https://chromium.googlesource.com/chromium/src/+/a6f723282862820eed7df3a375a3f922996d846e
3 years, 9 months ago (2017-03-02 00:46:59 UTC) #122
emaxx
https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc File chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc (right): https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc#newcode100 chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc:100: base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( On 2017/03/02 00:33:31, gab (slow - travel and ...
3 years, 9 months ago (2017-03-02 02:39:39 UTC) #123
gab
3 years, 9 months ago (2017-03-02 03:24:44 UTC) #124
Message was sent while issue was closed.
https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeo...
File chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc (right):

https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeo...
chrome/browser/chromeos/policy/server_backed_state_keys_broker.cc:100:
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
On 2017/03/02 02:39:39, emaxx wrote:
> On 2017/03/02 00:33:31, gab (slow - travel and perf) wrote:
> > On 2017/03/01 14:43:53, emaxx wrote:
> > > nit: #include "base/single_thread_task_runner.h"?
> > > I don't think we can rely here on
base/threading/thread_task_runner_handle.h
> > > including it.
> > 
> > By IWYU (include-what-you-use), thread_task_runner_handle.h has to include
> > single_thread_task_runner.h per returning it by value.
> 
> I'm not entirely following this argument. ThreadTaskRunnerHandle is returning
> SingleThreadTaskRunner not by a value, but inside a smart pointer. Incomplete
> types may be used in declarations with STL's smart pointers std::unique_ptr
and
> std::shared_ptr, and so do is with scoped_refptr - as documented here:
> https://cs.chromium.org/chromium/src/base/memory/ref_counted.h?l=392

https://groups.google.com/a/chromium.org/d/topic/chromium-dev/0khIRhxDq6E/dis...

(can't fwd-decl the pointer type of a scoped_refptr passed by value -- and the
documented/tested paradigm should be remove because it requires an advanced
fwd-template-decl which is literally never used outside of that test)

https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeo...
File chrome/browser/chromeos/policy/server_backed_state_keys_broker_unittest.cc
(right):

https://codereview.chromium.org/2657013002/diff/400001/chrome/browser/chromeo...
chrome/browser/chromeos/policy/server_backed_state_keys_broker_unittest.cc:71:
mocked_main_runner_->RunUntilIdle();
On 2017/03/02 02:39:39, emaxx wrote:
> On 2017/03/02 00:33:31, gab (slow - travel and perf) wrote:
> > On 2017/03/01 14:43:53, emaxx wrote:
> > > nit: #include "base/test/test_mock_time_task_runner.h"?
> > 
> > We had a similar discussion @
> > https://bugs.chromium.org/p/chromium/issues/detail?id=618793#c6.
> > 
> > Conclusion was that headers that always require another one to be at all
> useful
> > should include it and not require its users to include multiple headers
every
> > time.
> > 
> > i.e. jam@: "Stepping back, the purpose of IWYU is to avoid slowing down the
> > build by including unnecessary headers. In this case, the headers are always
> > necessary and will always be included by the source files anyways. So I
don't
> > see a negative."
> 
> The definition of the ScopedMockTimeMessageLoopTaskRunner class uses only
> pointers to TestMockTimeTaskRunner and scoped_refptr's to it. So technically,
> unless I'm missing something, it's not required for
> scoped_mock_time_message_loop_task_runner.h to include
> test_mock_time_task_runner.h.
> Therefore IWYU, in my opinion, still applies here: the header A is not
required
> to include header B, and not every consumer of A is required to include header
B
> - only if they want to dereference pointers to corresponding types.
> 
> Having said that, I don't have any intention to stand in the way of these
> changes. Just trying to understand the reasoning here and the scope of the
IWYU
> rule.

In pure IWYU sense you're right, but as was concluded in discussion on
aforementioned bug. It makes sense for
scoped_mock_time_message_loop_task_runner.h to provide
test_mock_timer_task_runner.h given it's merely a proxy to it (i.e. it doesn't
make sense to use this mock if you're not going to at least use the underlying
TestMockTimeTaskRunner* once).

Powered by Google App Engine
This is Rietveld 408576698