Commit a32641c8 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Fix some storage unit tests

A few of these tests have some subtle scheduling issues which are
hit when we attempt to turn on more granular Mojo bindings message
dispatch.

This CL adds some synchronization via FlushForTesting calls where
appropriate to avoid such issues.

TBR=sky@chromium.org

Bug: 869553
Change-Id: I8d4d5be6f670db3b3e369f70dfd987dc0b1f1ff2
Reviewed-on: https://chromium-review.googlesource.com/1159591
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580059}
parent c9f9a386
......@@ -1081,7 +1081,6 @@ TEST_F(LocalStorageContextMojoTestWithService, RecreateOnCommitFailure) {
area1->Put(key, value, base::nullopt, "source",
base::BindLambdaForTesting([&](bool success) {
EXPECT_TRUE(success);
put_loop.Quit();
}));
put_loop.RunUntilIdle();
values_written++;
......@@ -1093,6 +1092,7 @@ TEST_F(LocalStorageContextMojoTestWithService, RecreateOnCommitFailure) {
// Make sure all messages to the DB have been processed (Flush above merely
// schedules a commit, but there is no guarantee about those having been
// processed yet).
mock_leveldb_service.FlushBindingsForTesting();
if (mock_db)
mock_db->FlushForTesting();
// At this point enough commit failures should have happened to cause the
......
......@@ -663,7 +663,6 @@ TEST_F(SessionStorageContextMojoTest, RecreateOnCommitFailure) {
area1->Put(leveldb::StringPieceToUint8Vector("key"), value, base::nullopt,
"source", base::BindLambdaForTesting([&](bool success) {
EXPECT_TRUE(success);
put_loop.Quit();
}));
area1.FlushForTesting();
put_loop.RunUntilIdle();
......@@ -674,6 +673,7 @@ TEST_F(SessionStorageContextMojoTest, RecreateOnCommitFailure) {
// Make sure all messages to the DB have been processed (Flush above merely
// schedules a commit, but there is no guarantee about those having been
// processed yet).
fake_leveldb_service.FlushBindingsForTesting();
if (mock_db)
mock_db->FlushForTesting();
// At this point enough commit failures should have happened to cause the
......
......@@ -278,6 +278,8 @@ class StorageAreaImplTest : public testing::Test,
area->ScheduleImmediateCommit();
loop.Run();
}
db_.FlushBindingsForTesting();
}
const std::vector<Observation>& observations() { return observations_; }
......
......@@ -79,5 +79,9 @@ void FakeLevelDBService::Bind(
this, leveldb::mojom::LevelDBServiceRequest(std::move(interface_pipe)));
}
void FakeLevelDBService::FlushBindingsForTesting() {
bindings_.FlushForTesting();
}
} // namespace test
} // namespace content
......@@ -86,6 +86,8 @@ class FakeLevelDBService : public leveldb::mojom::LevelDBService {
mojo::ScopedMessagePipeHandle interface_pipe,
const service_manager::BindSourceInfo& source_info);
void FlushBindingsForTesting();
private:
mojo::BindingSet<leveldb::mojom::LevelDBService> bindings_;
......
......@@ -236,6 +236,10 @@ void FakeLevelDBDatabase::IteratorPrev(const base::UnguessableToken& iterator,
NOTREACHED();
}
void FakeLevelDBDatabase::FlushBindingsForTesting() {
bindings_.FlushForTesting();
}
std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>
FakeLevelDBDatabase::CopyPrefixedHelper(
const std::vector<uint8_t>& source_key_prefix,
......
......@@ -62,6 +62,8 @@ class FakeLevelDBDatabase : public leveldb::mojom::LevelDBDatabase {
void IteratorPrev(const base::UnguessableToken& iterator,
IteratorPrevCallback callback) override;
void FlushBindingsForTesting();
private:
std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>
CopyPrefixedHelper(const std::vector<uint8_t>& source_key_prefix,
......
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