summaryrefslogtreecommitdiff
path: root/update_manager/generic_variables_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/generic_variables_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/generic_variables_unittest.cc')
-rw-r--r--update_manager/generic_variables_unittest.cc30
1 files changed, 20 insertions, 10 deletions
diff --git a/update_manager/generic_variables_unittest.cc b/update_manager/generic_variables_unittest.cc
index 65f7f51e..372670f7 100644
--- a/update_manager/generic_variables_unittest.cc
+++ b/update_manager/generic_variables_unittest.cc
@@ -7,12 +7,15 @@
#include <memory>
#include <base/callback.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 <gtest/gtest.h>
-#include "update_engine/test_utils.h"
#include "update_engine/update_manager/umtest_utils.h"
-using chromeos_update_engine::test_utils::RunGMainLoopMaxIterations;
+using chromeos::MessageLoop;
+using chromeos::MessageLoopRunMaxIterations;
using std::unique_ptr;
namespace chromeos_update_manager {
@@ -132,11 +135,18 @@ TEST_F(UmCallCopyVariableTest, NullTest) {
}
class UmAsyncCopyVariableTest : public ::testing::Test {
- public:
+ protected:
+ void SetUp() override {
+ loop_.SetAsCurrent();
+ }
+
void TearDown() override {
// No remaining event on the main loop.
- EXPECT_EQ(0, RunGMainLoopMaxIterations(1));
+ EXPECT_FALSE(loop_.PendingTasks());
}
+
+
+ chromeos::FakeMessageLoop loop_{nullptr};
};
TEST_F(UmAsyncCopyVariableTest, ConstructorTest) {
@@ -150,7 +160,7 @@ TEST_F(UmAsyncCopyVariableTest, SetValueTest) {
var.SetValue(5);
UmTestUtils::ExpectVariableHasValue(5, &var);
// Execute all the pending observers.
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
}
TEST_F(UmAsyncCopyVariableTest, UnsetValueTest) {
@@ -158,7 +168,7 @@ TEST_F(UmAsyncCopyVariableTest, UnsetValueTest) {
var.UnsetValue();
UmTestUtils::ExpectVariableNotSet(&var);
// Execute all the pending observers.
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
}
class CallCounterObserver : public BaseVariable::ObserverInterface {
@@ -178,22 +188,22 @@ TEST_F(UmAsyncCopyVariableTest, ObserverCalledTest) {
// Check that a different value fires the notification.
var.SetValue(5);
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(1, observer.calls_count_);
// Check the same value doesn't.
var.SetValue(5);
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(1, observer.calls_count_);
// Check that unsetting a previously set value fires the notification.
var.UnsetValue();
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(2, observer.calls_count_);
// Check that unsetting again doesn't.
var.UnsetValue();
- RunGMainLoopMaxIterations(100);
+ MessageLoopRunMaxIterations(MessageLoop::current(), 100);
EXPECT_EQ(2, observer.calls_count_);
var.RemoveObserver(&observer);