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

Unified Diff: net/quic/quic_connection_helper_test.cc

Issue 26331009: Fix QuicConnectionHelper's alarm implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 7 years, 2 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 | « net/quic/quic_connection_helper.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_connection_helper_test.cc
diff --git a/net/quic/quic_connection_helper_test.cc b/net/quic/quic_connection_helper_test.cc
index e228d12cf49c34aa003ccf1dc8ebd24cc8df0489..4f248cc30a17a8030e855c0fa58796f41811db2a 100644
--- a/net/quic/quic_connection_helper_test.cc
+++ b/net/quic/quic_connection_helper_test.cc
@@ -38,6 +38,7 @@ class TestDelegate : public QuicAlarm::Delegate {
}
bool fired() const { return fired_; }
+ void Clear() { fired_= false; }
private:
bool fired_;
@@ -307,6 +308,35 @@ TEST_F(QuicConnectionHelperTest, CreateAlarmAndReset) {
EXPECT_TRUE(delegate->fired());
}
+TEST_F(QuicConnectionHelperTest, CreateAlarmAndResetEarlier) {
+ TestDelegate* delegate = new TestDelegate();
+ scoped_ptr<QuicAlarm> alarm(helper_->CreateAlarm(delegate));
+
+ QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(3);
+ alarm->Set(clock_.Now().Add(delta));
+ alarm->Cancel();
+ QuicTime::Delta new_delta = QuicTime::Delta::FromMicroseconds(1);
+ alarm->Set(clock_.Now().Add(new_delta));
+
+ // Both alarm tasks will be posted.
+ ASSERT_EQ(3u, runner_->GetPostedTasks().size());
+
+ // The earlier task will execute and will fire the alarm.
+ runner_->RunNextTask();
+ EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now());
+ EXPECT_TRUE(delegate->fired());
+ delegate->Clear();
+
+ // The latter task is still posted.
+ ASSERT_EQ(2u, runner_->GetPostedTasks().size());
+
+ // When the latter task is executed, the weak ptr will be invalid and
+ // the alarm will not fire.
+ runner_->RunNextTask();
+ EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now());
+ EXPECT_FALSE(delegate->fired());
+}
+
TEST_F(QuicConnectionHelperTest, TestRTORetransmission) {
AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
« no previous file with comments | « net/quic/quic_connection_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698