diff options
Diffstat (limited to 'update_manager/evaluation_context_unittest.cc')
-rw-r--r-- | update_manager/evaluation_context_unittest.cc | 114 |
1 files changed, 35 insertions, 79 deletions
diff --git a/update_manager/evaluation_context_unittest.cc b/update_manager/evaluation_context_unittest.cc index eb42eb74..fdb408b8 100644 --- a/update_manager/evaluation_context_unittest.cc +++ b/update_manager/evaluation_context_unittest.cc @@ -26,6 +26,7 @@ #include <gtest/gtest.h> #include "update_engine/common/fake_clock.h" +#include "update_engine/cros/fake_system_state.h" #include "update_engine/update_manager/fake_variable.h" #include "update_engine/update_manager/generic_variables.h" #include "update_engine/update_manager/mock_variable.h" @@ -39,6 +40,8 @@ using brillo::MessageLoop; using brillo::MessageLoopRunMaxIterations; using brillo::MessageLoopRunUntil; using chromeos_update_engine::FakeClock; +using chromeos_update_engine::FakeSystemState; +using std::shared_ptr; using std::string; using std::unique_ptr; using testing::_; @@ -59,14 +62,14 @@ bool GetBoolean(bool* value) { } template <typename T> -void ReadVar(scoped_refptr<EvaluationContext> ec, Variable<T>* var) { +void ReadVar(shared_ptr<EvaluationContext> ec, Variable<T>* var) { ec->GetValue(var); } // Runs |evaluation|; if the value pointed by |count_p| is greater than zero, // decrement it and schedule a reevaluation; otherwise, writes true to |done_p|. void EvaluateRepeatedly(Closure evaluation, - scoped_refptr<EvaluationContext> ec, + shared_ptr<EvaluationContext> ec, int* count_p, bool* done_p) { evaluation.Run(); @@ -87,16 +90,17 @@ void EvaluateRepeatedly(Closure evaluation, class UmEvaluationContextTest : public ::testing::Test { protected: void SetUp() override { + FakeSystemState::CreateInstance(); + fake_clock_ = FakeSystemState::Get()->fake_clock(); loop_.SetAsCurrent(); // Apr 22, 2009 19:25:00 UTC (this is a random reference point). - fake_clock_.SetMonotonicTime(Time::FromTimeT(1240428300)); + fake_clock_->SetMonotonicTime(Time::FromTimeT(1240428300)); // Mar 2, 2006 1:23:45 UTC. - fake_clock_.SetWallclockTime(Time::FromTimeT(1141262625)); - eval_ctx_ = new EvaluationContext( - &fake_clock_, + fake_clock_->SetWallclockTime(Time::FromTimeT(1141262625)); + eval_ctx_.reset(new EvaluationContext( default_timeout_, default_timeout_, - unique_ptr<base::Callback<void(EvaluationContext*)>>(nullptr)); + unique_ptr<base::Callback<void(EvaluationContext*)>>(nullptr))); } void TearDown() override { @@ -125,8 +129,8 @@ class UmEvaluationContextTest : public ::testing::Test { TimeDelta default_timeout_ = TimeDelta::FromSeconds(5); brillo::FakeMessageLoop loop_{nullptr}; - FakeClock fake_clock_; - scoped_refptr<EvaluationContext> eval_ctx_; + FakeClock* fake_clock_; + shared_ptr<EvaluationContext> eval_ctx_; // FakeVariables used for testing the EvaluationContext. These are required // here to prevent them from going away *before* the EvaluationContext under @@ -210,13 +214,7 @@ TEST_F(UmEvaluationContextTest, RunOnValueChangeOrTimeoutWithoutVariables) { fake_const_var_.reset(new string("Hello world!")); EXPECT_EQ(*eval_ctx_->GetValue(&fake_const_var_), "Hello world!"); - EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } // Test that reevaluation occurs when an async variable it depends on changes. @@ -286,23 +284,11 @@ TEST_F(UmEvaluationContextTest, RunOnValueChangeOrTimeoutExpires) { EXPECT_TRUE(value); // Ensure that we cannot reschedule an evaluation. - EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); // Ensure that we can reschedule an evaluation after resetting expiration. eval_ctx_->ResetExpiration(); - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } // Test that we clear the events when destroying the EvaluationContext. @@ -348,13 +334,7 @@ TEST_F(UmEvaluationContextTest, ObjectDeletedWithPendingEventsTest) { fake_poll_var_.reset(new string("Polled value")); eval_ctx_->GetValue(&fake_async_var_); eval_ctx_->GetValue(&fake_poll_var_); - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); // TearDown() checks for leaked observers on this async_variable, which means // that our object is still alive after removing its reference. } @@ -388,8 +368,8 @@ TEST_F(UmEvaluationContextTest, DefaultTimeout) { } TEST_F(UmEvaluationContextTest, TimeoutUpdatesWithMonotonicTime) { - fake_clock_.SetMonotonicTime(fake_clock_.GetMonotonicTime() + - TimeDelta::FromSeconds(1)); + fake_clock_->SetMonotonicTime(fake_clock_->GetMonotonicTime() + + TimeDelta::FromSeconds(1)); TimeDelta timeout = default_timeout_ - TimeDelta::FromSeconds(1); @@ -398,9 +378,9 @@ TEST_F(UmEvaluationContextTest, TimeoutUpdatesWithMonotonicTime) { } TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesWallclock) { - Time cur_time = fake_clock_.GetWallclockTime(); + Time cur_time = fake_clock_->GetWallclockTime(); // Advance the time on the clock but don't call ResetEvaluation yet. - fake_clock_.SetWallclockTime(cur_time + TimeDelta::FromSeconds(4)); + fake_clock_->SetWallclockTime(cur_time + TimeDelta::FromSeconds(4)); EXPECT_TRUE(eval_ctx_->IsWallclockTimeGreaterThan(cur_time - TimeDelta::FromSeconds(1))); @@ -410,7 +390,7 @@ TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesWallclock) { // Call ResetEvaluation now, which should use the new evaluation time. eval_ctx_->ResetEvaluation(); - cur_time = fake_clock_.GetWallclockTime(); + cur_time = fake_clock_->GetWallclockTime(); EXPECT_TRUE(eval_ctx_->IsWallclockTimeGreaterThan(cur_time - TimeDelta::FromSeconds(1))); EXPECT_FALSE(eval_ctx_->IsWallclockTimeGreaterThan(cur_time)); @@ -419,9 +399,9 @@ TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesWallclock) { } TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesMonotonic) { - Time cur_time = fake_clock_.GetMonotonicTime(); + Time cur_time = fake_clock_->GetMonotonicTime(); // Advance the time on the clock but don't call ResetEvaluation yet. - fake_clock_.SetMonotonicTime(cur_time + TimeDelta::FromSeconds(4)); + fake_clock_->SetMonotonicTime(cur_time + TimeDelta::FromSeconds(4)); EXPECT_TRUE(eval_ctx_->IsMonotonicTimeGreaterThan(cur_time - TimeDelta::FromSeconds(1))); @@ -431,7 +411,7 @@ TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesMonotonic) { // Call ResetEvaluation now, which should use the new evaluation time. eval_ctx_->ResetEvaluation(); - cur_time = fake_clock_.GetMonotonicTime(); + cur_time = fake_clock_->GetMonotonicTime(); EXPECT_TRUE(eval_ctx_->IsMonotonicTimeGreaterThan(cur_time - TimeDelta::FromSeconds(1))); EXPECT_FALSE(eval_ctx_->IsMonotonicTimeGreaterThan(cur_time)); @@ -442,33 +422,21 @@ TEST_F(UmEvaluationContextTest, ResetEvaluationResetsTimesMonotonic) { TEST_F(UmEvaluationContextTest, IsWallclockTimeGreaterThanSignalsTriggerReevaluation) { EXPECT_FALSE(eval_ctx_->IsWallclockTimeGreaterThan( - fake_clock_.GetWallclockTime() + TimeDelta::FromSeconds(1))); + fake_clock_->GetWallclockTime() + TimeDelta::FromSeconds(1))); // The "false" from IsWallclockTimeGreaterThan means that's not that timestamp // yet, so this should schedule a callback for when that happens. - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } TEST_F(UmEvaluationContextTest, IsMonotonicTimeGreaterThanSignalsTriggerReevaluation) { EXPECT_FALSE(eval_ctx_->IsMonotonicTimeGreaterThan( - fake_clock_.GetMonotonicTime() + TimeDelta::FromSeconds(1))); + fake_clock_->GetMonotonicTime() + TimeDelta::FromSeconds(1))); // The "false" from IsMonotonicTimeGreaterThan means that's not that timestamp // yet, so this should schedule a callback for when that happens. - EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_TRUE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } TEST_F(UmEvaluationContextTest, @@ -476,18 +444,12 @@ TEST_F(UmEvaluationContextTest, // IsWallclockTimeGreaterThan() should ignore timestamps on the past for // reevaluation. EXPECT_TRUE(eval_ctx_->IsWallclockTimeGreaterThan( - fake_clock_.GetWallclockTime() - TimeDelta::FromSeconds(20))); + fake_clock_->GetWallclockTime() - TimeDelta::FromSeconds(20))); EXPECT_TRUE(eval_ctx_->IsWallclockTimeGreaterThan( - fake_clock_.GetWallclockTime() - TimeDelta::FromSeconds(1))); + fake_clock_->GetWallclockTime() - TimeDelta::FromSeconds(1))); // Callback should not be scheduled. - EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } TEST_F(UmEvaluationContextTest, @@ -495,18 +457,12 @@ TEST_F(UmEvaluationContextTest, // IsMonotonicTimeGreaterThan() should ignore timestamps on the past for // reevaluation. EXPECT_TRUE(eval_ctx_->IsMonotonicTimeGreaterThan( - fake_clock_.GetMonotonicTime() - TimeDelta::FromSeconds(20))); + fake_clock_->GetMonotonicTime() - TimeDelta::FromSeconds(20))); EXPECT_TRUE(eval_ctx_->IsMonotonicTimeGreaterThan( - fake_clock_.GetMonotonicTime() - TimeDelta::FromSeconds(1))); + fake_clock_->GetMonotonicTime() - TimeDelta::FromSeconds(1))); // Callback should not be scheduled. - EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout( -#if BASE_VER < 576279 - Bind(&base::DoNothing) -#else - base::DoNothing() -#endif - )); + EXPECT_FALSE(eval_ctx_->RunOnValueChangeOrTimeout(base::DoNothing())); } TEST_F(UmEvaluationContextTest, DumpContext) { |