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

Unified Diff: google_apis/gcm/engine/mcs_client_unittest.cc

Issue 383993006: [GCM] Add a SelectiveAck test for midstream acks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gcm/engine/mcs_client_unittest.cc
diff --git a/google_apis/gcm/engine/mcs_client_unittest.cc b/google_apis/gcm/engine/mcs_client_unittest.cc
index 915b25d18db18ae23eb49fdf67cb9166d1c948ef..e7fd27c931eebe45cb96633467da0e30918323a2 100644
--- a/google_apis/gcm/engine/mcs_client_unittest.cc
+++ b/google_apis/gcm/engine/mcs_client_unittest.cc
@@ -548,6 +548,76 @@ TEST_F(MCSClientTest, SendMessageRMQPartialAckOnReconnect) {
EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
}
+// Receive some messages. Send some messages. Receive a selective acknowledging
+// the sent messages. Restart. No messages should be resent, and no messages
+// should be acked by the client, as the server acknowledged the stream ack.
+TEST_F(MCSClientTest, SelectiveAckMidStream) {
+ BuildMCSClient();
+ InitializeClient();
+ LoginClient(std::vector<std::string>());
+
+ // Server stream id 2. Acknowledges client stream id 0 (login).
+ MCSMessage sMessage1(BuildDataMessage(
+ "from", "category", "X", 0, "s1", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ReceiveMessage(sMessage1);
+ WaitForMCSEvent();
+ PumpLoop();
+
+ // Client stream id 1. Acknowledges server stream id 2.
+ MCSMessage cMessage1(BuildDataMessage(
+ "from", "category", "Y", 2, "1", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ExpectOutgoingMessage(cMessage1);
+ mcs_client()->SendMessage(cMessage1);
+ PumpLoop();
+ EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
+
+ // Server stream id 3. Acknowledges client stream id 1, and ack of server
+ // stream id 2.
+ MCSMessage sMessage2(BuildDataMessage(
+ "from", "category", "X", 1, "s2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ReceiveMessage(sMessage2);
+ WaitForMCSEvent();
+ PumpLoop();
+
+ // Client Stream id 2. Acknowledges server id 3.
+ MCSMessage cMessage2(BuildDataMessage(
+ "from", "category", "Y", 3, "2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ExpectOutgoingMessage(cMessage2);
+ mcs_client()->SendMessage(cMessage2);
+ PumpLoop();
+ EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
+
+ // Receive an acknowledgment for the client message 1. Should also ack
+ // the ack for the server message 2, but not server message.
fgorski 2014/07/14 20:59:35 Please use the ids of messages consistently, and p
Nicolas Zea 2014/07/14 21:16:18 Done.
+ // Message "2" should also be resent, acking stream id 4.
+ MCSMessage cMessage3(BuildDataMessage(
+ "from", "category", "Y", 4, "2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ExpectOutgoingMessage(cMessage3);
+ std::vector<std::string> acked_ids(1, "1");
+ scoped_ptr<mcs_proto::IqStanza> ack(BuildSelectiveAck(acked_ids));
+ GetFakeHandler()->ReceiveMessage(
+ MCSMessage(kIqStanzaTag,
+ ack.PassAs<const google::protobuf::MessageLite>()));
+ WaitForMCSEvent();
+ PumpLoop();
+ EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
+
+ // Rebuild the client. Message "20" should be acked as part of login,
fgorski 2014/07/14 20:59:35 what do you mean by "20"?
Nicolas Zea 2014/07/14 21:16:18 Oops, typo. Fixed.
+ // and message "2" should be resent.
+ StoreCredentials();
+ BuildMCSClient();
+ InitializeClient();
+
+ acked_ids[0] = "s2";
+ LoginClient(acked_ids);
+
+ MCSMessage cMessage4(BuildDataMessage(
+ "from", "category", "Y", 1, "2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ExpectOutgoingMessage(cMessage4);
+ PumpLoop();
+ EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
+}
+
// Receive some messages. On restart, the login request should contain the
// appropriate acknowledged ids.
TEST_F(MCSClientTest, AckOnLogin) {
« google_apis/gcm/engine/mcs_client.cc ('K') | « google_apis/gcm/engine/mcs_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698