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

Side by Side Diff: dbus/end_to_end_async_unittest.cc

Issue 10492005: dbus: Fix a subtle butterfly-effect bug in handling incoming messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "dbus/bus.h" 16 #include "dbus/bus.h"
17 #include "dbus/message.h" 17 #include "dbus/message.h"
18 #include "dbus/object_path.h" 18 #include "dbus/object_path.h"
19 #include "dbus/object_proxy.h" 19 #include "dbus/object_proxy.h"
20 #include "dbus/test_service.h" 20 #include "dbus/test_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace {
24
25 // See comments in ObjectProxy::RunResponseCallback() for why the number was
26 // chosen.
27 const int kHugePayloadSize = 64 << 20; // 64 MB
28
29 } // namespace
30
23 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and 31 // The end-to-end test exercises the asynchronous APIs in ObjectProxy and
24 // ExportedObject. 32 // ExportedObject.
25 class EndToEndAsyncTest : public testing::Test { 33 class EndToEndAsyncTest : public testing::Test {
26 public: 34 public:
27 EndToEndAsyncTest() { 35 EndToEndAsyncTest() {
28 } 36 }
29 37
30 virtual void SetUp() { 38 virtual void SetUp() {
31 // Make the main thread not to allow IO. 39 // Make the main thread not to allow IO.
32 base::ThreadRestrictions::SetIOAllowed(false); 40 base::ThreadRestrictions::SetIOAllowed(false);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 314
307 // Check the responses. 315 // Check the responses.
308 WaitForResponses(3); 316 WaitForResponses(3);
309 // Sort as the order of the returned messages is not deterministic. 317 // Sort as the order of the returned messages is not deterministic.
310 std::sort(response_strings_.begin(), response_strings_.end()); 318 std::sort(response_strings_.begin(), response_strings_.end());
311 EXPECT_EQ("bar", response_strings_[0]); 319 EXPECT_EQ("bar", response_strings_[0]);
312 EXPECT_EQ("baz", response_strings_[1]); 320 EXPECT_EQ("baz", response_strings_[1]);
313 EXPECT_EQ("foo", response_strings_[2]); 321 EXPECT_EQ("foo", response_strings_[2]);
314 } 322 }
315 323
324 TEST_F(EndToEndAsyncTest, Echo_HugePayload) {
325 const std::string kHugePayload(kHugePayloadSize, 'o');
326
327 // Create the method call with a huge payload.
328 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
329 dbus::MessageWriter writer(&method_call);
330 writer.AppendString(kHugePayload);
331
332 // Call the method.
333 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
334 CallMethod(&method_call, timeout_ms);
335
336 // This caused a DCHECK failure before. Ensure that the issue is fixed.
337 WaitForResponses(1);
338 EXPECT_EQ(kHugePayload, response_strings_[0]);
339 }
340
316 TEST_F(EndToEndAsyncTest, BrokenBus) { 341 TEST_F(EndToEndAsyncTest, BrokenBus) {
317 const char* kHello = "hello"; 342 const char* kHello = "hello";
318 343
319 // Set up a broken bus. 344 // Set up a broken bus.
320 SetUpBrokenBus(); 345 SetUpBrokenBus();
321 346
322 // Create the method call. 347 // Create the method call.
323 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); 348 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
324 dbus::MessageWriter writer(&method_call); 349 dbus::MessageWriter writer(&method_call);
325 writer.AppendString(kHello); 350 writer.AppendString(kHello);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // |object_proxy_| should not handle it, and should leave it for the root 555 // |object_proxy_| should not handle it, and should leave it for the root
531 // object proxy |root_object_proxy_|. 556 // object proxy |root_object_proxy_|.
532 test_service_->SendTestSignalFromRoot(kMessage); 557 test_service_->SendTestSignalFromRoot(kMessage);
533 WaitForTestSignal(); 558 WaitForTestSignal();
534 // Verify the signal was not received by the specific proxy. 559 // Verify the signal was not received by the specific proxy.
535 ASSERT_TRUE(test_signal_string_.empty()); 560 ASSERT_TRUE(test_signal_string_.empty());
536 // Verify the string WAS received by the root proxy. 561 // Verify the string WAS received by the root proxy.
537 ASSERT_EQ(kMessage, root_test_signal_string_); 562 ASSERT_EQ(kMessage, root_test_signal_string_);
538 } 563 }
539 564
565 TEST_F(EndToEndAsyncTest, TestHugeSignal) {
566 const std::string kHugeMessage(kHugePayloadSize, 'o');
567
568 // Send the huge signal from the exported object.
569 test_service_->SendTestSignal(kHugeMessage);
570 // This caused a DCHECK failure before. Ensure that the issue is fixed.
571 WaitForTestSignal();
572 ASSERT_EQ(kHugeMessage, test_signal_string_);
573 }
574
540 class SignalReplacementTest : public EndToEndAsyncTest { 575 class SignalReplacementTest : public EndToEndAsyncTest {
541 public: 576 public:
542 SignalReplacementTest() { 577 SignalReplacementTest() {
543 } 578 }
544 579
545 virtual void SetUp() { 580 virtual void SetUp() {
546 // Set up base class. 581 // Set up base class.
547 EndToEndAsyncTest::SetUp(); 582 EndToEndAsyncTest::SetUp();
548 583
549 // Reconnect the root object proxy's signal handler to a new handler 584 // Reconnect the root object proxy's signal handler to a new handler
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 const char kMessage[] = "hello, world"; 620 const char kMessage[] = "hello, world";
586 // Send the test signal from the exported object. 621 // Send the test signal from the exported object.
587 test_service_->SendTestSignal(kMessage); 622 test_service_->SendTestSignal(kMessage);
588 // Receive the signal with the object proxy. 623 // Receive the signal with the object proxy.
589 WaitForTestSignal(); 624 WaitForTestSignal();
590 // Verify the string WAS NOT received by the original handler. 625 // Verify the string WAS NOT received by the original handler.
591 ASSERT_TRUE(test_signal_string_.empty()); 626 ASSERT_TRUE(test_signal_string_.empty());
592 // Verify the signal WAS received by the replacement handler. 627 // Verify the signal WAS received by the replacement handler.
593 ASSERT_EQ(kMessage, replacement_test_signal_string_); 628 ASSERT_EQ(kMessage, replacement_test_signal_string_);
594 } 629 }
OLDNEW
« no previous file with comments | « no previous file | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698