From 3eeba6d73e171488e5cfb78d5217e46a0b6f6db9 Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:51:26 -0700 Subject: [PATCH] Add blocking toggle to SetPersistentSettings. (#896) (#951) Add blocking toggle to SetPersistentSettings to wait for CommitPendingWrite() to complete. Greatly improves reliability and accuracy of persistent_settings_test especially now that sleep can be removed. Added blocking toggle to RemovePersistentSettings as well. Replaces ASSERT with EXPECT when inside of closures that depend on test_done.Signal() to avoid deadlocking. b/280430510 b/283529011 (cherry picked from commit e024a33d9cb1e7ae41c06431138955c5f93dfd41) Co-authored-by: Brian Ting --- .../persistent_storage/persistent_settings.cc | 18 +- .../persistent_storage/persistent_settings.h | 22 ++- .../persistent_settings_test.cc | 179 +++++++++--------- 3 files changed, 116 insertions(+), 103 deletions(-) diff --git a/cobalt/persistent_storage/persistent_settings.cc b/cobalt/persistent_storage/persistent_settings.cc index c4db3685a114..c93ff54c37cb 100644 --- a/cobalt/persistent_storage/persistent_settings.cc +++ b/cobalt/persistent_storage/persistent_settings.cc @@ -201,7 +201,7 @@ PersistentSettings::GetPersistentSettingAsDictionary(const std::string& key) { void PersistentSettings::SetPersistentSetting( const std::string& key, std::unique_ptr value, - base::OnceClosure closure) { + base::OnceClosure closure, bool blocking) { if (key == kValidated) { LOG(ERROR) << "Cannot set protected persistent setting: " << key; return; @@ -209,12 +209,12 @@ void PersistentSettings::SetPersistentSetting( message_loop()->task_runner()->PostTask( FROM_HERE, base::BindOnce(&PersistentSettings::SetPersistentSettingHelper, base::Unretained(this), key, std::move(value), - std::move(closure))); + std::move(closure), blocking)); } void PersistentSettings::SetPersistentSettingHelper( const std::string& key, std::unique_ptr value, - base::OnceClosure closure) { + base::OnceClosure closure, bool blocking) { DCHECK_EQ(base::MessageLoop::current(), message_loop()); if (validated_initial_settings_) { base::AutoLock auto_lock(pref_store_lock_); @@ -223,7 +223,7 @@ void PersistentSettings::SetPersistentSettingHelper( WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); writeable_pref_store()->SetValue( key, std::move(value), WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); - writeable_pref_store()->CommitPendingWrite(); + commit_pending_write(blocking); } else { LOG(ERROR) << "Cannot set persistent setting while unvalidated: " << key; } @@ -231,15 +231,17 @@ void PersistentSettings::SetPersistentSettingHelper( } void PersistentSettings::RemovePersistentSetting(const std::string& key, - base::OnceClosure closure) { + base::OnceClosure closure, + bool blocking) { message_loop()->task_runner()->PostTask( FROM_HERE, base::BindOnce(&PersistentSettings::RemovePersistentSettingHelper, - base::Unretained(this), key, std::move(closure))); + base::Unretained(this), key, std::move(closure), + blocking)); } void PersistentSettings::RemovePersistentSettingHelper( - const std::string& key, base::OnceClosure closure) { + const std::string& key, base::OnceClosure closure, bool blocking) { DCHECK_EQ(base::MessageLoop::current(), message_loop()); if (validated_initial_settings_) { base::AutoLock auto_lock(pref_store_lock_); @@ -248,7 +250,7 @@ void PersistentSettings::RemovePersistentSettingHelper( WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); writeable_pref_store()->RemoveValue( key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); - writeable_pref_store()->CommitPendingWrite(); + commit_pending_write(blocking); } else { LOG(ERROR) << "Cannot remove persistent setting while unvalidated: " << key; } diff --git a/cobalt/persistent_storage/persistent_settings.h b/cobalt/persistent_storage/persistent_settings.h index 0cf789f6b367..ff3ea58439bc 100644 --- a/cobalt/persistent_storage/persistent_settings.h +++ b/cobalt/persistent_storage/persistent_settings.h @@ -71,11 +71,13 @@ class PersistentSettings : public base::MessageLoop::DestructionObserver { void SetPersistentSetting( const std::string& key, std::unique_ptr value, - base::OnceClosure closure = std::move(base::DoNothing())); + base::OnceClosure closure = std::move(base::DoNothing()), + bool blocking = false); void RemovePersistentSetting( const std::string& key, - base::OnceClosure closure = std::move(base::DoNothing())); + base::OnceClosure closure = std::move(base::DoNothing()), + bool blocking = false); void DeletePersistentSettings( base::OnceClosure closure = std::move(base::DoNothing())); @@ -89,10 +91,10 @@ class PersistentSettings : public base::MessageLoop::DestructionObserver { void SetPersistentSettingHelper(const std::string& key, std::unique_ptr value, - base::OnceClosure closure); + base::OnceClosure closure, bool blocking); void RemovePersistentSettingHelper(const std::string& key, - base::OnceClosure closure); + base::OnceClosure closure, bool blocking); void DeletePersistentSettingsHelper(base::OnceClosure closure); @@ -101,6 +103,18 @@ class PersistentSettings : public base::MessageLoop::DestructionObserver { return pref_store_; } + void commit_pending_write(bool blocking) { + if (blocking) { + base::WaitableEvent written; + writeable_pref_store()->CommitPendingWrite( + base::OnceClosure(), + base::BindOnce(&base::WaitableEvent::Signal, Unretained(&written))); + written.Wait(); + } else { + writeable_pref_store()->CommitPendingWrite(); + } + } + // Persistent settings file path. std::string persistent_settings_file_; diff --git a/cobalt/persistent_storage/persistent_settings_test.cc b/cobalt/persistent_storage/persistent_settings_test.cc index 3f883971aa1d..91b2bce682b3 100644 --- a/cobalt/persistent_storage/persistent_settings_test.cc +++ b/cobalt/persistent_storage/persistent_settings_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "cobalt/persistent_storage/persistent_settings.h" + #include #include @@ -20,9 +22,7 @@ #include "base/callback_forward.h" #include "base/synchronization/waitable_event.h" #include "base/test/scoped_task_environment.h" -#include "base/threading/platform_thread.h" #include "base/values.h" -#include "cobalt/persistent_storage/persistent_settings.h" #include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/configuration_constants.h" @@ -81,13 +81,13 @@ TEST_F(PersistentSettingTest, GetDefaultBool) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsInt("key", true)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(4.2), std::move(closure)); + "key", std::make_unique(4.2), std::move(closure), true); test_done_.Wait(); } @@ -99,32 +99,32 @@ TEST_F(PersistentSettingTest, GetSetBool) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(true), std::move(closure)); + "key", std::make_unique(true), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_FALSE( + EXPECT_FALSE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_FALSE( + EXPECT_FALSE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(false), std::move(closure)); + "key", std::make_unique(false), std::move(closure), true); test_done_.Wait(); } @@ -143,13 +143,13 @@ TEST_F(PersistentSettingTest, GetDefaultInt) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ(8, persistent_settings->GetPersistentSettingAsInt("key", 8)); + EXPECT_EQ(8, persistent_settings->GetPersistentSettingAsInt("key", 8)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(4.2), std::move(closure)); + "key", std::make_unique(4.2), std::move(closure), true); test_done_.Wait(); } @@ -161,36 +161,36 @@ TEST_F(PersistentSettingTest, GetSetInt) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ(-1, persistent_settings->GetPersistentSettingAsInt("key", 8)); + EXPECT_EQ(-1, persistent_settings->GetPersistentSettingAsInt("key", 8)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(-1), std::move(closure)); + "key", std::make_unique(-1), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ(0, persistent_settings->GetPersistentSettingAsInt("key", 8)); + EXPECT_EQ(0, persistent_settings->GetPersistentSettingAsInt("key", 8)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(0), std::move(closure)); + "key", std::make_unique(0), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ(42, persistent_settings->GetPersistentSettingAsInt("key", 8)); + EXPECT_EQ(42, persistent_settings->GetPersistentSettingAsInt("key", 8)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(42), std::move(closure)); + "key", std::make_unique(42), std::move(closure), true); test_done_.Wait(); } @@ -214,13 +214,13 @@ TEST_F(PersistentSettingTest, GetDefaultString) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ("hello", persistent_settings->GetPersistentSettingAsString( + EXPECT_EQ("hello", persistent_settings->GetPersistentSettingAsString( "key", "hello")); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(4.2), std::move(closure)); + "key", std::make_unique(4.2), std::move(closure), true); test_done_.Wait(); } @@ -232,21 +232,21 @@ TEST_F(PersistentSettingTest, GetSetString) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ("", persistent_settings->GetPersistentSettingAsString( + EXPECT_EQ("", persistent_settings->GetPersistentSettingAsString( "key", "hello")); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(""), std::move(closure)); + "key", std::make_unique(""), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ( + EXPECT_EQ( "hello there", persistent_settings->GetPersistentSettingAsString("key", "hello")); test_done->Signal(); @@ -254,46 +254,47 @@ TEST_F(PersistentSettingTest, GetSetString) { persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique("hello there"), std::move(closure)); + "key", std::make_unique("hello there"), std::move(closure), + true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ("42", persistent_settings->GetPersistentSettingAsString( + EXPECT_EQ("42", persistent_settings->GetPersistentSettingAsString( "key", "hello")); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique("42"), std::move(closure)); + "key", std::make_unique("42"), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ("\n", persistent_settings->GetPersistentSettingAsString( + EXPECT_EQ("\n", persistent_settings->GetPersistentSettingAsString( "key", "hello")); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique("\n"), std::move(closure)); + "key", std::make_unique("\n"), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_EQ("\\n", persistent_settings->GetPersistentSettingAsString( + EXPECT_EQ("\\n", persistent_settings->GetPersistentSettingAsString( "key", "hello")); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique("\\n"), std::move(closure)); + "key", std::make_unique("\\n"), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); } @@ -307,10 +308,10 @@ TEST_F(PersistentSettingTest, GetSetList) { [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { auto test_list = persistent_settings->GetPersistentSettingAsList("key"); - ASSERT_FALSE(test_list.empty()); - ASSERT_EQ(1, test_list.size()); - ASSERT_TRUE(test_list[0].is_string()); - ASSERT_EQ("hello", test_list[0].GetString()); + EXPECT_FALSE(test_list.empty()); + EXPECT_EQ(1, test_list.size()); + EXPECT_TRUE(test_list[0].is_string()); + EXPECT_EQ("hello", test_list[0].GetString()); test_done->Signal(); }, persistent_settings.get(), &test_done_); @@ -318,7 +319,7 @@ TEST_F(PersistentSettingTest, GetSetList) { std::vector list; list.emplace_back("hello"); persistent_settings->SetPersistentSetting( - "key", std::make_unique(list), std::move(closure)); + "key", std::make_unique(list), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); @@ -326,19 +327,19 @@ TEST_F(PersistentSettingTest, GetSetList) { [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { auto test_list = persistent_settings->GetPersistentSettingAsList("key"); - ASSERT_FALSE(test_list.empty()); - ASSERT_EQ(2, test_list.size()); - ASSERT_TRUE(test_list[0].is_string()); - ASSERT_EQ("hello", test_list[0].GetString()); - ASSERT_TRUE(test_list[1].is_string()); - ASSERT_EQ("there", test_list[1].GetString()); + EXPECT_FALSE(test_list.empty()); + EXPECT_EQ(2, test_list.size()); + EXPECT_TRUE(test_list[0].is_string()); + EXPECT_EQ("hello", test_list[0].GetString()); + EXPECT_TRUE(test_list[1].is_string()); + EXPECT_EQ("there", test_list[1].GetString()); test_done->Signal(); }, persistent_settings.get(), &test_done_); list.emplace_back("there"); persistent_settings->SetPersistentSetting( - "key", std::make_unique(list), std::move(closure)); + "key", std::make_unique(list), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); @@ -346,21 +347,21 @@ TEST_F(PersistentSettingTest, GetSetList) { [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { auto test_list = persistent_settings->GetPersistentSettingAsList("key"); - ASSERT_FALSE(test_list.empty()); - ASSERT_EQ(3, test_list.size()); - ASSERT_TRUE(test_list[0].is_string()); - ASSERT_EQ("hello", test_list[0].GetString()); - ASSERT_TRUE(test_list[1].is_string()); - ASSERT_EQ("there", test_list[1].GetString()); - ASSERT_TRUE(test_list[2].is_int()); - ASSERT_EQ(42, test_list[2].GetInt()); + EXPECT_FALSE(test_list.empty()); + EXPECT_EQ(3, test_list.size()); + EXPECT_TRUE(test_list[0].is_string()); + EXPECT_EQ("hello", test_list[0].GetString()); + EXPECT_TRUE(test_list[1].is_string()); + EXPECT_EQ("there", test_list[1].GetString()); + EXPECT_TRUE(test_list[2].is_int()); + EXPECT_EQ(42, test_list[2].GetInt()); test_done->Signal(); }, persistent_settings.get(), &test_done_); list.emplace_back(42); persistent_settings->SetPersistentSetting( - "key", std::make_unique(list), std::move(closure)); + "key", std::make_unique(list), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); } @@ -375,10 +376,10 @@ TEST_F(PersistentSettingTest, GetSetDictionary) { base::WaitableEvent* test_done) { auto test_dict = persistent_settings->GetPersistentSettingAsDictionary("key"); - ASSERT_FALSE(test_dict.empty()); - ASSERT_EQ(1, test_dict.size()); - ASSERT_TRUE(test_dict["key_string"]->is_string()); - ASSERT_EQ("hello", test_dict["key_string"]->GetString()); + EXPECT_FALSE(test_dict.empty()); + EXPECT_EQ(1, test_dict.size()); + EXPECT_TRUE(test_dict["key_string"]->is_string()); + EXPECT_EQ("hello", test_dict["key_string"]->GetString()); test_done->Signal(); }, persistent_settings.get(), &test_done_); @@ -386,7 +387,7 @@ TEST_F(PersistentSettingTest, GetSetDictionary) { base::flat_map> dict; dict.try_emplace("key_string", std::make_unique("hello")); persistent_settings->SetPersistentSetting( - "key", std::make_unique(dict), std::move(closure)); + "key", std::make_unique(dict), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); @@ -395,19 +396,19 @@ TEST_F(PersistentSettingTest, GetSetDictionary) { base::WaitableEvent* test_done) { auto test_dict = persistent_settings->GetPersistentSettingAsDictionary("key"); - ASSERT_FALSE(test_dict.empty()); - ASSERT_EQ(2, test_dict.size()); - ASSERT_TRUE(test_dict["key_string"]->is_string()); - ASSERT_EQ("hello", test_dict["key_string"]->GetString()); - ASSERT_TRUE(test_dict["key_int"]->is_int()); - ASSERT_EQ(42, test_dict["key_int"]->GetInt()); + EXPECT_FALSE(test_dict.empty()); + EXPECT_EQ(2, test_dict.size()); + EXPECT_TRUE(test_dict["key_string"]->is_string()); + EXPECT_EQ("hello", test_dict["key_string"]->GetString()); + EXPECT_TRUE(test_dict["key_int"]->is_int()); + EXPECT_EQ(42, test_dict["key_int"]->GetInt()); test_done->Signal(); }, persistent_settings.get(), &test_done_); dict.try_emplace("key_int", std::make_unique(42)); persistent_settings->SetPersistentSetting( - "key", std::make_unique(dict), std::move(closure)); + "key", std::make_unique(dict), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); } @@ -425,10 +426,10 @@ TEST_F(PersistentSettingTest, URLAsKey) { base::WaitableEvent* test_done) { auto test_dict = persistent_settings->GetPersistentSettingAsDictionary( "http://127.0.0.1:45019/"); - ASSERT_FALSE(test_dict.empty()); - ASSERT_EQ(1, test_dict.size()); - ASSERT_TRUE(test_dict["http://127.0.0.1:45019/"]->is_string()); - ASSERT_EQ("Dictionary URL Key Works!", + EXPECT_FALSE(test_dict.empty()); + EXPECT_EQ(1, test_dict.size()); + EXPECT_TRUE(test_dict["http://127.0.0.1:45019/"]->is_string()); + EXPECT_EQ("Dictionary URL Key Works!", test_dict["http://127.0.0.1:45019/"]->GetString()); test_done->Signal(); }, @@ -441,7 +442,7 @@ TEST_F(PersistentSettingTest, URLAsKey) { std::make_unique("Dictionary URL Key Works!")); persistent_settings->SetPersistentSetting("http://127.0.0.1:45019/", std::make_unique(dict), - std::move(closure)); + std::move(closure), true); test_done_.Wait(); test_done_.Reset(); @@ -450,12 +451,12 @@ TEST_F(PersistentSettingTest, URLAsKey) { base::WaitableEvent* test_done) { auto test_dict = persistent_settings->GetPersistentSettingAsDictionary( "http://127.0.0.1:45019/"); - ASSERT_TRUE(test_dict.empty()); + EXPECT_TRUE(test_dict.empty()); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->RemovePersistentSetting("http://127.0.0.1:45019/", - std::move(closure)); + std::move(closure), true); test_done_.Wait(); test_done_.Reset(); } @@ -471,29 +472,29 @@ TEST_F(PersistentSettingTest, RemoveSetting) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(true), std::move(closure)); + "key", std::make_unique(true), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_FALSE( + EXPECT_FALSE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); - persistent_settings->RemovePersistentSetting("key", std::move(closure)); + persistent_settings->RemovePersistentSetting("key", std::move(closure), true); test_done_.Wait(); test_done_.Reset(); } @@ -509,24 +510,24 @@ TEST_F(PersistentSettingTest, DeleteSettings) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(true), std::move(closure)); + "key", std::make_unique(true), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_FALSE( + EXPECT_FALSE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, @@ -547,22 +548,18 @@ TEST_F(PersistentSettingTest, InvalidSettings) { base::OnceClosure closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(true), std::move(closure)); + "key", std::make_unique(true), std::move(closure), true); test_done_.Wait(); test_done_.Reset(); - // Sleep for one second to allow for the previous persistent_setting's - // JsonPrefStore instance time to write to disk before creating a new - // persistent_settings and JsonPrefStore instance. - base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); persistent_settings = std::make_unique(kPersistentSettingsJson); ASSERT_TRUE(persistent_settings->GetPersistentSettingAsBool("key", true)); @@ -571,15 +568,15 @@ TEST_F(PersistentSettingTest, InvalidSettings) { closure = base::BindOnce( [](PersistentSettings* persistent_settings, base::WaitableEvent* test_done) { - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", true)); - ASSERT_TRUE( + EXPECT_TRUE( persistent_settings->GetPersistentSettingAsBool("key", false)); test_done->Signal(); }, persistent_settings.get(), &test_done_); persistent_settings->SetPersistentSetting( - "key", std::make_unique(false), std::move(closure)); + "key", std::make_unique(false), std::move(closure), true); test_done_.Wait(); test_done_.Reset();