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

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: Address comments 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
« no previous file with comments | « google_apis/gcm/engine/mcs_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6b23084bb9cbcd4e161fce80499dfbfd20421800 100644
--- a/google_apis/gcm/engine/mcs_client_unittest.cc
+++ b/google_apis/gcm/engine/mcs_client_unittest.cc
@@ -548,6 +548,83 @@ TEST_F(MCSClientTest, SendMessageRMQPartialAckOnReconnect) {
EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
}
+// Handle a selective ack that only acks some messages. The remaining unacked
+// messages should be resent. On restart, those same unacked messages should be
+// resent, and any pending acks for incoming messages should also be resent.
+TEST_F(MCSClientTest, SelectiveAckMidStream) {
+ BuildMCSClient();
+ InitializeClient();
+ LoginClient(std::vector<std::string>());
+
+ // Server stream id 2 ("s1").
+ // Acks 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 ("1").
+ // Acks server stream id 2 ("s1").
+ 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 ("s2").
+ // Acks client stream id 1 ("1").
+ // Confirms ack of server stream id 2 ("s1").
+ MCSMessage sMessage2(BuildDataMessage(
+ "from", "category", "X", 1, "s2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ReceiveMessage(sMessage2);
+ WaitForMCSEvent();
+ PumpLoop();
+
+ // Client Stream id 2 ("2").
+ // Acks server stream id 3 ("s2").
+ MCSMessage cMessage2(BuildDataMessage(
+ "from", "category", "Y", 3, "2", kTTLValue, 1, 0, "", 0));
+ GetFakeHandler()->ExpectOutgoingMessage(cMessage2);
+ mcs_client()->SendMessage(cMessage2);
+ PumpLoop();
+ EXPECT_TRUE(GetFakeHandler()->AllOutgoingMessagesReceived());
+
+ // Simulate the last message being dropped by having the server selectively
+ // ack client message "1".
+ // Client message "2" should be resent, acking server stream id 4 (selective
+ // ack).
+ 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 without any further acks from server. Note that this
+ // resets the stream ids.
+ // Sever message "s2" should be acked as part of login.
+ // Client 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) {
« no previous file with comments | « 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