Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "google_apis/gcm/engine/mcs_client.h" | 5 #include "google_apis/gcm/engine/mcs_client.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 541 } |
| 542 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); | 542 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); |
| 543 GetFakeHandler()->ReceiveMessage( | 543 GetFakeHandler()->ReceiveMessage( |
| 544 MCSMessage(kIqStanzaTag, | 544 MCSMessage(kIqStanzaTag, |
| 545 ack.PassAs<const google::protobuf::MessageLite>())); | 545 ack.PassAs<const google::protobuf::MessageLite>())); |
| 546 WaitForMCSEvent(); | 546 WaitForMCSEvent(); |
| 547 PumpLoop(); | 547 PumpLoop(); |
| 548 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | 548 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); |
| 549 } | 549 } |
| 550 | 550 |
| 551 // Handle a selective ack that only acks some messages. The remaining unacked | |
| 552 // messages should be resent. On restart, those same unacked messages should be | |
| 553 // resent, and any pending acks for incoming messages should also be resent. | |
| 554 TEST_F(MCSClientTest, SelectiveAckMidStream) { | |
| 555 BuildMCSClient(); | |
| 556 InitializeClient(); | |
| 557 LoginClient(std::vector<std::string>()); | |
| 558 | |
| 559 // Server stream id 2 ("s1"). | |
| 560 // Acks client stream id 0 (login). | |
| 561 MCSMessage sMessage1(BuildDataMessage( | |
| 562 "from", "category", "X", 0, "s1", kTTLValue, 1, 0, "", 0)); | |
| 563 GetFakeHandler()->ReceiveMessage(sMessage1); | |
| 564 WaitForMCSEvent(); | |
| 565 PumpLoop(); | |
| 566 | |
| 567 // Client stream id 1 ("1"). | |
| 568 // Acks server stream id 2 ("s1"). | |
| 569 MCSMessage cMessage1(BuildDataMessage( | |
| 570 "from", "category", "Y", 2, "1", kTTLValue, 1, 0, "", 0)); | |
| 571 GetFakeHandler()->ExpectOutgoingMessage(cMessage1); | |
| 572 mcs_client()->SendMessage(cMessage1); | |
| 573 PumpLoop(); | |
| 574 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
| 575 | |
| 576 // Server stream id 3 ("s2"). | |
| 577 // Acks client stream id 1 ("1"). | |
| 578 // Confirms ack of server stream id 2 ("s1"). | |
| 579 MCSMessage sMessage2(BuildDataMessage( | |
| 580 "from", "category", "X", 1, "s2", kTTLValue, 1, 0, "", 0)); | |
| 581 GetFakeHandler()->ReceiveMessage(sMessage2); | |
| 582 WaitForMCSEvent(); | |
| 583 PumpLoop(); | |
| 584 | |
| 585 // Client Stream id 2 ("2"). | |
| 586 // Acks server stream id 3 ("s2"). | |
| 587 MCSMessage cMessage2(BuildDataMessage( | |
| 588 "from", "category", "Y", 3, "2", kTTLValue, 1, 0, "", 0)); | |
| 589 GetFakeHandler()->ExpectOutgoingMessage(cMessage2); | |
| 590 mcs_client()->SendMessage(cMessage2); | |
| 591 PumpLoop(); | |
| 592 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
| 593 | |
| 594 // Simulate the last message being dropped by having the server selectively | |
| 595 // ack client message "1". | |
| 596 // Client message "2" should be resent, acking server stream id 4 (selective | |
| 597 // ack). | |
| 598 MCSMessage cMessage3(BuildDataMessage( | |
| 599 "from", "category", "Y", 4, "2", kTTLValue, 1, 0, "", 0)); | |
| 600 GetFakeHandler()->ExpectOutgoingMessage(cMessage3); | |
| 601 std::vector<std::string> acked_ids(1, "1"); | |
| 602 scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids)); | |
| 603 GetFakeHandler()->ReceiveMessage( | |
| 604 MCSMessage(kIqStanzaTag, | |
| 605 ack.PassAs<const google::protobuf::MessageLite>())); | |
| 606 WaitForMCSEvent(); | |
| 607 PumpLoop(); | |
| 608 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
| 609 | |
| 610 // Rebuild the client without any further acks from server. | |
|
fgorski
2014/07/15 04:07:58
nit: Does this reset the server stream id? If so,
Nicolas Zea
2014/07/16 17:58:32
Done.
| |
| 611 // Sever message "s2" should be acked as part of login. | |
| 612 // Client message "2" should be resent. | |
| 613 StoreCredentials(); | |
| 614 BuildMCSClient(); | |
| 615 InitializeClient(); | |
| 616 | |
| 617 acked_ids[0] = "s2"; | |
| 618 LoginClient(acked_ids); | |
| 619 | |
| 620 MCSMessage cMessage4(BuildDataMessage( | |
| 621 "from", "category", "Y", 1, "2", kTTLValue, 1, 0, "", 0)); | |
| 622 GetFakeHandler()->ExpectOutgoingMessage(cMessage4); | |
| 623 PumpLoop(); | |
| 624 EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived()); | |
| 625 } | |
| 626 | |
| 551 // Receive some messages. On restart, the login request should contain the | 627 // Receive some messages. On restart, the login request should contain the |
| 552 // appropriate acknowledged ids. | 628 // appropriate acknowledged ids. |
| 553 TEST_F(MCSClientTest, AckOnLogin) { | 629 TEST_F(MCSClientTest, AckOnLogin) { |
| 554 BuildMCSClient(); | 630 BuildMCSClient(); |
| 555 InitializeClient(); | 631 InitializeClient(); |
| 556 LoginClient(std::vector<std::string>()); | 632 LoginClient(std::vector<std::string>()); |
| 557 | 633 |
| 558 // Receive some messages. | 634 // Receive some messages. |
| 559 std::vector<std::string> id_list; | 635 std::vector<std::string> id_list; |
| 560 for (int i = 1; i <= kMessageBatchSize; ++i) { | 636 for (int i = 1; i <= kMessageBatchSize; ++i) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 | 866 |
| 791 LoginClient(std::vector<std::string>()); | 867 LoginClient(std::vector<std::string>()); |
| 792 GetFakeHandler()->ExpectOutgoingMessage(message); | 868 GetFakeHandler()->ExpectOutgoingMessage(message); |
| 793 GetFakeHandler()->ExpectOutgoingMessage(message2); | 869 GetFakeHandler()->ExpectOutgoingMessage(message2); |
| 794 PumpLoop(); | 870 PumpLoop(); |
| 795 } | 871 } |
| 796 | 872 |
| 797 } // namespace | 873 } // namespace |
| 798 | 874 |
| 799 } // namespace gcm | 875 } // namespace gcm |
| OLD | NEW |