summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 09:48:08 +0000
committerzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 09:48:08 +0000
commita1ce083005fa664f7a80da4eca1700b534c4185c (patch)
treed1b9b4fbc46d48a12e8207ddb4c5edfd857a2292 /google_apis
parent5d7495738335bbd2014c4eb3e8df998530f0e1db (diff)
downloadchromium_src-a1ce083005fa664f7a80da4eca1700b534c4185c.zip
chromium_src-a1ce083005fa664f7a80da4eca1700b534c4185c.tar.gz
chromium_src-a1ce083005fa664f7a80da4eca1700b534c4185c.tar.bz2
[GCM] Add a SelectiveAck test for midstream acks
SelectiveAck was over confirming due to unsigned in misuse. This adds a test that exercises the confirm logic used by SelectiveAck. BUG=392664 Review URL: https://codereview.chromium.org/383993006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gcm/engine/mcs_client.cc6
-rw-r--r--google_apis/gcm/engine/mcs_client_unittest.cc77
2 files changed, 82 insertions, 1 deletions
diff --git a/google_apis/gcm/engine/mcs_client.cc b/google_apis/gcm/engine/mcs_client.cc
index a99a333..fbabda1 100644
--- a/google_apis/gcm/engine/mcs_client.cc
+++ b/google_apis/gcm/engine/mcs_client.cc
@@ -770,7 +770,7 @@ void MCSClient::HandleStreamAck(StreamId last_stream_id_received) {
void MCSClient::HandleSelectiveAck(const PersistentIdList& id_list) {
std::set<PersistentId> remaining_ids(id_list.begin(), id_list.end());
- StreamId last_stream_id_received = -1;
+ StreamId last_stream_id_received = 0;
// First check the to_resend_ queue. Acknowledgments are always contiguous,
// so if there's a pending message that hasn't been acked, all newer messages
@@ -839,6 +839,10 @@ void MCSClient::HandleSelectiveAck(const PersistentIdList& id_list) {
to_send_.push_front(to_resend_.back());
to_resend_.pop_back();
}
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&MCSClient::MaybeSendMessage,
+ weak_ptr_factory_.GetWeakPtr()));
}
void MCSClient::HandleServerConfirmedReceipt(StreamId device_stream_id) {
diff --git a/google_apis/gcm/engine/mcs_client_unittest.cc b/google_apis/gcm/engine/mcs_client_unittest.cc
index 915b25d..6b23084 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) {