summaryrefslogtreecommitdiff
path: root/update_manager/update_manager_unittest.cc
diff options
context:
space:
mode:
authorAlex Deymo <deymo@chromium.org>2015-06-10 14:11:05 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-13 02:53:26 +0000
commit509dd5376f47e38d18fe7d29da776e3dc9a9786d (patch)
tree75ca22d28383fdace928a6c591cda54c88c30e27 /update_manager/update_manager_unittest.cc
parentcc169259cd4451d6bf23c04ed07ac69a1d4d9444 (diff)
update_engine: Convert update_manager to chromeos::MessageLoop.
The update_manager/event_loop.* files were basically an abstraction of the glib main loop in order to make it easier to replace it later. This patch removes those files and replaces their functions with the chromeos::MessageLoop interface, backing it up with a FakeMessageLoop during test, and a real GlibMessageLoop during normal execution. This patch reduces the running time of the unittest considerably since there is no need to wait for the timeouts. BUG=chromium:419827,chromium:402066 TEST=Unittest still pass. Tested on a link device that the UM still runs. Change-Id: Id572248ff4c9c8be7226ef8c653a5c94ab9c1677 Reviewed-on: https://chromium-review.googlesource.com/276892 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'update_manager/update_manager_unittest.cc')
-rw-r--r--update_manager/update_manager_unittest.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/update_manager/update_manager_unittest.cc b/update_manager/update_manager_unittest.cc
index 1d79c5c2..cf097fa4 100644
--- a/update_manager/update_manager_unittest.cc
+++ b/update_manager/update_manager_unittest.cc
@@ -14,12 +14,15 @@
#include <vector>
#include <base/bind.h>
+#include <base/test/simple_test_clock.h>
#include <base/time/time.h>
+#include <chromeos/message_loops/fake_message_loop.h>
+#include <chromeos/message_loops/message_loop.h>
+#include <chromeos/message_loops/message_loop_utils.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "update_engine/fake_clock.h"
-#include "update_engine/test_utils.h"
#include "update_engine/update_manager/default_policy.h"
#include "update_engine/update_manager/fake_state.h"
#include "update_engine/update_manager/mock_policy.h"
@@ -29,9 +32,10 @@ using base::Bind;
using base::Callback;
using base::Time;
using base::TimeDelta;
+using chromeos::MessageLoop;
+using chromeos::MessageLoopRunMaxIterations;
using chromeos_update_engine::ErrorCode;
using chromeos_update_engine::FakeClock;
-using chromeos_update_engine::test_utils::RunGMainLoopMaxIterations;
using std::pair;
using std::string;
using std::tuple;
@@ -61,11 +65,18 @@ namespace chromeos_update_manager {
class UmUpdateManagerTest : public ::testing::Test {
protected:
void SetUp() override {
+ loop_.SetAsCurrent();
fake_state_ = new FakeState();
umut_.reset(new UpdateManager(&fake_clock_, TimeDelta::FromSeconds(5),
TimeDelta::FromSeconds(1), fake_state_));
}
+ void TearDown() override {
+ EXPECT_FALSE(loop_.PendingTasks());
+ }
+
+ base::SimpleTestClock test_clock_;
+ chromeos::FakeMessageLoop loop_{&test_clock_};
FakeState* fake_state_; // Owned by the umut_.
FakeClock fake_clock_;
unique_ptr<UpdateManager> umut_;
@@ -231,7 +242,7 @@ TEST_F(UmUpdateManagerTest, AsyncPolicyRequestDelaysEvaluation) {
umut_->AsyncPolicyRequest(callback, &Policy::UpdateCheckAllowed);
// The callback should wait until we run the main loop for it to be executed.
EXPECT_EQ(0, calls.size());
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(1, calls.size());
}
@@ -248,14 +259,14 @@ TEST_F(UmUpdateManagerTest, AsyncPolicyRequestTimeoutDoesNotFire) {
umut_->AsyncPolicyRequest(callback, &Policy::UpdateCheckAllowed);
// Run the main loop, ensure that policy was attempted once before deferring
// to the default.
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(1, num_called);
ASSERT_EQ(1, calls.size());
EXPECT_EQ(EvalStatus::kSucceeded, calls[0].first);
// Wait for the timeout to expire, run the main loop again, ensure that
// nothing happened.
- sleep(2);
- RunGMainLoopMaxIterations(10);
+ test_clock_.Advance(TimeDelta::FromSeconds(2));
+ MessageLoopRunMaxIterations(MessageLoop::current(), 10);
EXPECT_EQ(1, num_called);
EXPECT_EQ(1, calls.size());
}
@@ -276,24 +287,24 @@ TEST_F(UmUpdateManagerTest, AsyncPolicyRequestTimesOut) {
umut_->AsyncPolicyRequest(callback, &Policy::UpdateCheckAllowed);
// Run the main loop, ensure that policy was attempted once but the callback
// was not invoked.
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(1, num_called);
EXPECT_EQ(0, calls.size());
// Wait for the expiration timeout to expire, run the main loop again,
// ensure that reevaluation occurred but callback was not invoked (i.e.
// default policy was not consulted).
- sleep(2);
+ test_clock_.Advance(TimeDelta::FromSeconds(2));
fake_clock_.SetWallclockTime(fake_clock_.GetWallclockTime() +
TimeDelta::FromSeconds(2));
- RunGMainLoopMaxIterations(10);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 10);
EXPECT_EQ(2, num_called);
EXPECT_EQ(0, calls.size());
// Wait for reevaluation due to delay to happen, ensure that it occurs and
// that the callback is invoked.
- sleep(2);
+ test_clock_.Advance(TimeDelta::FromSeconds(2));
fake_clock_.SetWallclockTime(fake_clock_.GetWallclockTime() +
TimeDelta::FromSeconds(2));
- RunGMainLoopMaxIterations(10);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 10);
EXPECT_EQ(3, num_called);
ASSERT_EQ(1, calls.size());
EXPECT_EQ(EvalStatus::kSucceeded, calls[0].first);