Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1092)

Unified Diff: dbus/signal_sender_verification_unittest.cc

Issue 11358111: Make SignalSenderVerificationTest more robust (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dbus/test_service.h » ('j') | dbus/test_service.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/signal_sender_verification_unittest.cc
diff --git a/dbus/signal_sender_verification_unittest.cc b/dbus/signal_sender_verification_unittest.cc
index 5179fffd5e2aeeb860395530dbcf388ebf7abad2..56276584c9ce926d88900de04aadd0c0d1549b26 100644
--- a/dbus/signal_sender_verification_unittest.cc
+++ b/dbus/signal_sender_verification_unittest.cc
@@ -42,6 +42,7 @@ class SignalSenderVerificationTest : public testing::Test {
ASSERT_TRUE(test_service_->StartService());
ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted());
ASSERT_TRUE(test_service_->HasDBusThread());
+ ASSERT_TRUE(test_service_->HasOwnership());
// Same setup for the second TestService. This service should not have the
// ownership of the name at this point.
@@ -49,6 +50,7 @@ class SignalSenderVerificationTest : public testing::Test {
ASSERT_TRUE(test_service2_->StartService());
ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted());
ASSERT_TRUE(test_service2_->HasDBusThread());
+ ASSERT_FALSE(test_service2_->HasOwnership());
// Create the client, using the D-Bus thread.
dbus::Bus::Options bus_options;
@@ -75,6 +77,14 @@ class SignalSenderVerificationTest : public testing::Test {
message_loop_.Run();
}
+ void OnOwnership(bool expected, bool success) {
+ ASSERT_EQ(expected, success);
+ message_loop_.PostTask(
+ FROM_HERE,
+ base::Bind(&SignalSenderVerificationTest::QuitMessageLoop,
+ base::Unretained(this)));
+ }
+
virtual void TearDown() {
bus_->ShutdownOnDBusThreadAndBlock();
@@ -115,6 +125,10 @@ class SignalSenderVerificationTest : public testing::Test {
message_loop_.Run();
}
+ void QuitMessageLoop() {
+ message_loop_.Quit();
+ }
+
MessageLoop message_loop_;
scoped_ptr<base::Thread> dbus_thread_;
scoped_refptr<dbus::Bus> bus_;
@@ -169,7 +183,15 @@ TEST_F(SignalSenderVerificationTest, TestOwnerChanged) {
// Release and aquire the name ownership.
test_service_->ShutdownAndBlock();
- test_service2_->RequestOwnership();
+ // It takes some time for D-Bus to free the ownership of "TestService".
+ base::PlatformThread::Sleep(TestTimeouts::action_timeout());
satorux1 2012/11/07 01:42:25 Sleep should be avoided. Can we monitor the owners
Haruki Sato 2012/11/12 04:59:43 Thank you for the advice! Replaced with NameOwnerC
+ test_service2_->RequestOwnership(
+ base::Bind(&SignalSenderVerificationTest::OnOwnership,
+ base::Unretained(this),
+ true));
+ // OnOwnership will PostTask to quit the message loop.
+ message_loop_.Run();
+ ASSERT_TRUE(test_service2_->HasOwnership());
// Now the second service owns the name.
const char kNewMessage[] = "hello, new world";
« no previous file with comments | « no previous file | dbus/test_service.h » ('j') | dbus/test_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698