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

Unified Diff: net/websockets/websocket_job_unittest.cc

Issue 18932005: Reduce the complexity of WebSocketThrottle's wakeup code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android_dbg build fix Created 7 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 | « net/websockets/websocket_job.cc ('k') | net/websockets/websocket_throttle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_job_unittest.cc
diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc
index 28ba53cc12b2ad738548683818b68782f4dcf823..3ce52790cba95a19086ddf4b7fae6d2ad2692b82 100644
--- a/net/websockets/websocket_job_unittest.cc
+++ b/net/websockets/websocket_job_unittest.cc
@@ -392,7 +392,7 @@ class WebSocketJobTest : public PlatformTest,
}
void SkipToConnecting() {
websocket_->state_ = WebSocketJob::CONNECTING;
- WebSocketThrottle::GetInstance()->PutInQueue(websocket_.get());
+ ASSERT_TRUE(WebSocketThrottle::GetInstance()->PutInQueue(websocket_.get()));
}
WebSocketJob::State GetWebSocketJobState() {
return websocket_->state_;
@@ -432,6 +432,7 @@ class WebSocketJobTest : public PlatformTest,
void TestInvalidSendData();
void TestConnectByWebSocket(ThrottlingOption throttling);
void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling);
+ void TestThrottlingLimit();
SpdyWebSocketTestUtil spdy_util_;
StreamType stream_type_;
@@ -821,7 +822,8 @@ void WebSocketJobTest::TestConnectByWebSocket(
// Create former WebSocket object which obstructs the latter one.
block_websocket = new WebSocketJob(NULL);
block_websocket->addresses_ = AddressList(websocket_->address_list());
- WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get());
+ ASSERT_TRUE(
+ WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get()));
}
websocket_->Connect();
@@ -832,10 +834,9 @@ void WebSocketJobTest::TestConnectByWebSocket(
// Remove the former WebSocket object from throttling queue to unblock the
// latter.
- WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
block_websocket->state_ = WebSocketJob::CLOSED;
+ WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
block_websocket = NULL;
- WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
}
EXPECT_EQ(OK, WaitForResult());
@@ -950,7 +951,8 @@ void WebSocketJobTest::TestConnectBySpdy(
// Create former WebSocket object which obstructs the latter one.
block_websocket = new WebSocketJob(NULL);
block_websocket->addresses_ = AddressList(websocket_->address_list());
- WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get());
+ ASSERT_TRUE(
+ WebSocketThrottle::GetInstance()->PutInQueue(block_websocket.get()));
}
websocket_->Connect();
@@ -961,10 +963,9 @@ void WebSocketJobTest::TestConnectBySpdy(
// Remove the former WebSocket object from throttling queue to unblock the
// latter.
- WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
block_websocket->state_ = WebSocketJob::CLOSED;
+ WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
block_websocket = NULL;
- WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
}
EXPECT_EQ(OK, WaitForResult());
@@ -973,6 +974,33 @@ void WebSocketJobTest::TestConnectBySpdy(
EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
}
+void WebSocketJobTest::TestThrottlingLimit() {
+ std::vector<scoped_refptr<WebSocketJob> > jobs;
+ const int kMaxWebSocketJobsThrottled = 1024;
+ IPAddressNumber ip;
+ ParseIPLiteralToNumber("127.0.0.1", &ip);
+ for (int i = 0; i < kMaxWebSocketJobsThrottled + 1; ++i) {
+ scoped_refptr<WebSocketJob> job = new WebSocketJob(NULL);
+ job->addresses_ = AddressList(AddressList::CreateFromIPAddress(ip, 80));
+ if (i >= kMaxWebSocketJobsThrottled)
+ EXPECT_FALSE(WebSocketThrottle::GetInstance()->PutInQueue(job));
+ else
+ EXPECT_TRUE(WebSocketThrottle::GetInstance()->PutInQueue(job));
+ jobs.push_back(job);
+ }
+
+ // Close the jobs in reverse order. Otherwise, We need to make them prepared
+ // for Wakeup call.
+ for (std::vector<scoped_refptr<WebSocketJob> >::reverse_iterator iter =
+ jobs.rbegin();
+ iter != jobs.rend();
+ ++iter) {
+ WebSocketJob* job = (*iter).get();
+ job->state_ = WebSocketJob::CLOSED;
+ WebSocketThrottle::GetInstance()->RemoveFromQueue(job);
+ }
+}
+
// Execute tests in both spdy-disabled mode and spdy-enabled mode.
TEST_P(WebSocketJobTest, SimpleHandshake) {
WebSocketJob::set_websocket_over_spdy_enabled(false);
@@ -1059,6 +1087,10 @@ TEST_P(WebSocketJobTest, ThrottlingWebSocket) {
TestConnectByWebSocket(THROTTLING_ON);
}
+TEST_P(WebSocketJobTest, ThrottlingMaxNumberOfThrottledJobLimit) {
+ TestThrottlingLimit();
+}
+
TEST_P(WebSocketJobTest, ThrottlingWebSocketSpdyEnabled) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
TestConnectByWebSocket(THROTTLING_ON);
« no previous file with comments | « net/websockets/websocket_job.cc ('k') | net/websockets/websocket_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698