Commit 0347d9d8 authored by pavely's avatar pavely Committed by Commit bot

Fix flakiness of SyncFakeServerTestCase.testSyncTypedURLDeleteFromServer

The test was flaky because after triggering sync cycle it immediately checked
for entity count condition without waiting for sync cycle to complete. I've
verified that test fails consistently after adding delay in sync cycle.

I've added WaitUntilConditionOrTimeout.

BUG=672286
R=bzanotti@chromium.org

Review-Url: https://codereview.chromium.org/2610303002
Cr-Commit-Position: refs/heads/master@{#441703}
parent 6261e2b7
...@@ -112,6 +112,24 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) { ...@@ -112,6 +112,24 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
testing::WaitUntilConditionOrTimeout(kSyncOperationTimeout, condition), testing::WaitUntilConditionOrTimeout(kSyncOperationTimeout, condition),
@"Expected %d entities of the specified type", entity_count); @"Expected %d entities of the specified type", entity_count);
} }
// Waits for |entity_count| entities of type |entity_type| with name |name|, and
// fails with a GREYAssert if the condition is not met, within a short period of
// time.
void AssertNumberOfEntitiesWithName(int entity_count,
syncer::ModelType entity_type,
std::string name) {
ConditionBlock condition = ^{
NSError* error = nil;
BOOL success = chrome_test_util::VerifyNumberOfSyncEntitiesWithName(
entity_type, name, entity_count, &error);
DCHECK(success || error);
return !!success;
};
GREYAssert(
testing::WaitUntilConditionOrTimeout(kSyncOperationTimeout, condition),
@"Expected %d entities of the specified type", entity_count);
}
} // namespace } // namespace
// Hermetic sync tests, which use the fake sync server. // Hermetic sync tests, which use the fake sync server.
...@@ -534,7 +552,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) { ...@@ -534,7 +552,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
// Test that typed url is deleted from client after server sends tombstone for // Test that typed url is deleted from client after server sends tombstone for
// that typed url. // that typed url.
- (void)FLAKY_testSyncTypedURLDeleteFromServer { - (void)testSyncTypedURLDeleteFromServer {
const GURL mockURL("http://not-a-real-site/"); const GURL mockURL("http://not-a-real-site/");
chrome_test_util::ClearBrowsingHistory(); chrome_test_util::ClearBrowsingHistory();
...@@ -553,17 +571,12 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) { ...@@ -553,17 +571,12 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
AssertSyncInitialized(YES); AssertSyncInitialized(YES);
chrome_test_util::TriggerSyncCycle(syncer::TYPED_URLS); chrome_test_util::TriggerSyncCycle(syncer::TYPED_URLS);
NSError* error = nil; AssertNumberOfEntitiesWithName(1, syncer::TYPED_URLS, mockURL.spec());
BOOL success = chrome_test_util::VerifyNumberOfSyncEntitiesWithName(
syncer::TYPED_URLS, mockURL.spec(), 1, &error);
DCHECK(success || error);
GREYAssertTrue(success, [error localizedDescription]);
chrome_test_util::DeleteTypedUrlFromClient(mockURL); chrome_test_util::DeleteTypedUrlFromClient(mockURL);
// Trigger sync and wait for fake server to be updated. // Trigger sync and wait for fake server to be updated.
chrome_test_util::TriggerSyncCycle(syncer::TYPED_URLS); chrome_test_util::TriggerSyncCycle(syncer::TYPED_URLS);
__block NSError* blockSafeError = nil; __block NSError* blockSafeError = nil;
GREYCondition* condition = [GREYCondition GREYCondition* condition = [GREYCondition
conditionWithName:@"Wait for typed URL to be downloaded." conditionWithName:@"Wait for typed URL to be downloaded."
...@@ -574,7 +587,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) { ...@@ -574,7 +587,7 @@ void AssertNumberOfEntities(int entity_count, syncer::ModelType entity_type) {
blockSafeError = [error copy]; blockSafeError = [error copy];
return result; return result;
}]; }];
success = [condition waitWithTimeout:kSyncOperationTimeout]; BOOL success = [condition waitWithTimeout:kSyncOperationTimeout];
DCHECK(success || blockSafeError); DCHECK(success || blockSafeError);
if (blockSafeError) { if (blockSafeError) {
[blockSafeError autorelease]; [blockSafeError autorelease];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment