-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leave sync chain after 5 seconds without ack response #10044
Conversation
|
||
bool deleted_device_info_sent = false; | ||
base::RunLoop loop; | ||
bridge()->DeleteDeviceInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test actually last for 6 seconds. Not sure, is that possible to make it instant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please take a look at base::ScopedMockTimeMessageLoopTaskRunner
. it can be used to fast-forward delayed PostTask
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Playing with ScopedMockTimeMessageLoopTaskRunner
didn't gave a good result, but scoped_mock_time_message_loop_task_runner.h
contains a comment
// Note: Use TaskEnvironment + TimeSource::MOCK_TIME instead of this in unit
// tests.
It turned out DeviceInfoSyncBridgeTest
already uses TaskEnvironment
so to avoid patches I have to make BraveDeviceInfoSyncBridgeTest
with TaskEnvironment(MOCK_TIME)
to run LocalDeleteWhenOffline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about test::TaskEnvironment::FastForwardBy(base::TimeDelta::FromSeconds(6))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, just tried, but this didn't help.
Comments near the FastForwardBy
says
// Only valid for instances using TimeSource::MOCK_TIME.
and I got DCHECK(mock_time_domain_);
fired. Original task_environment
for DeviceInfoSyncBridgeTest
is created without MOCK_TIME
flag and I have to make a new BraveDeviceInfoSyncBridgeTest
with MOCK_TIME
- then it doesn't require to call `FastForwardBy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about this?
namespace base {
namespace test {
namespace {
class TaskEnvironmentOptionalMockTime : public TaskEnvironment {
public:
TaskEnvironmentOptionalMockTime()
: TaskEnvironment(
IsMockTimedTest(
testing::UnitTest::GetInstance()->current_test_info()->name())
? TimeSource::MOCK_TIME
: TimeSource::DEFAULT) {}
static bool IsMockTimedTest(base::StringPiece test_name) {
return test_name == "LocalDeleteWhenOffline";
}
};
} // namespace
} // namespace test
} // namespace base
#define TaskEnvironment TaskEnvironmentOptionalMockTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goodov this is cool and this works 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed fix, thanks @goodov
dbc2afe
to
6f354b8
Compare
6f354b8
to
75a60e5
Compare
|
||
bool deleted_device_info_sent = false; | ||
base::RunLoop loop; | ||
bridge()->DeleteDeviceInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please take a look at base::ScopedMockTimeMessageLoopTaskRunner
. it can be used to fast-forward delayed PostTask
.
ASSERT_EQ(2, change_count()); | ||
|
||
const std::string kLocalGuid = CacheGuidForSuffix(kLocalSuffix); | ||
ON_CALL(*processor(), IsEntityUnsynced(kLocalGuid)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's possible to count this calls? Also it seems ok to copy "5" into test and not introduce a public getter for tests. or just make a constant as extern so it can be used in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I have addressed both this notices.
Calls are counted at EXPECT_CALL(*processor(), IsEntityUnsynced).Times(5);
and I replaced the getter with hard-coded value of 5.
75a60e5
to
5882178
Compare
5882178
to
edc2c2a
Compare
} // namespace test | ||
} // namespace base | ||
|
||
#define TaskEnvironment TaskEnvironmentOptionalMockTime | ||
|
||
#include "../../../../components/sync_device_info/device_info_sync_bridge_unittest.cc" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#undef TaskEnvironment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. thanks, fixed.
edc2c2a
to
243e3b2
Compare
|
||
loop.Run(); | ||
|
||
EXPECT_EQ(5, bridge()->GetDeviceDeleteAttemptsForTest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that we can drop this when we started to count IsEntityUnsynced
calls. wdyt? it would be a little cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, with that was possible to remove both GetDeviceDeleteAttemptsForTest
and device_delete_attempts_for_test_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approve, but consider removing GetDeviceDeleteAttemptsForTest
.
243e3b2
to
07db889
Compare
Resolves brave/brave-browser#18054
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Start a new Sync Chain
Computer
Manage your synced devices
(brave://settings/braveSync/setup)Leave Sync Chain
,Transport State Disabled
.