summaryrefslogtreecommitdiffstats
path: root/net/test
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 19:17:29 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 19:17:29 +0000
commitfb1692aa4d8d8269cc5e30f92eec2820dcf0ec92 (patch)
tree692d02df58f6ab7c9e432412631db61ae24c1e18 /net/test
parentb15a08ac0f726393605383e242e8d9b6c35acdeb (diff)
downloadchromium_src-fb1692aa4d8d8269cc5e30f92eec2820dcf0ec92.zip
chromium_src-fb1692aa4d8d8269cc5e30f92eec2820dcf0ec92.tar.gz
chromium_src-fb1692aa4d8d8269cc5e30f92eec2820dcf0ec92.tar.bz2
GTTF: Make EmbeddedTestServer always use its own thread for IO
Otherwise we likely end up blocking the browser's IO thread, especially with big responses that don't fit in the kernel buffer. This blocks EmbeddedTestServer's IO thread, and if it's also the browser's IO thread the browser can't consume the response resulting in a hang. BUG=310713 R=jam@chromium.org, rch@chromium.org Review URL: https://codereview.chromium.org/37683004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r--net/test/embedded_test_server/embedded_test_server.cc28
-rw-r--r--net/test/embedded_test_server/embedded_test_server.h11
-rw-r--r--net/test/embedded_test_server/embedded_test_server_unittest.cc4
3 files changed, 23 insertions, 20 deletions
diff --git a/net/test/embedded_test_server/embedded_test_server.cc b/net/test/embedded_test_server/embedded_test_server.cc
index 128597f..4bd68fe 100644
--- a/net/test/embedded_test_server/embedded_test_server.cc
+++ b/net/test/embedded_test_server/embedded_test_server.cc
@@ -99,13 +99,15 @@ HttpListenSocket::~HttpListenSocket() {
DCHECK(thread_checker_.CalledOnValidThread());
}
-EmbeddedTestServer::EmbeddedTestServer(
- const scoped_refptr<base::SingleThreadTaskRunner>& io_thread)
- : io_thread_(io_thread),
+EmbeddedTestServer::EmbeddedTestServer()
+ : io_thread_("EmbeddedTestServer io thread"),
port_(-1),
weak_factory_(this) {
- DCHECK(io_thread_.get());
DCHECK(thread_checker_.CalledOnValidThread());
+
+ base::Thread::Options thread_options;
+ thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
+ CHECK(io_thread_.StartWithOptions(thread_options));
}
EmbeddedTestServer::~EmbeddedTestServer() {
@@ -135,7 +137,7 @@ bool EmbeddedTestServer::ShutdownAndWaitUntilComplete() {
}
void EmbeddedTestServer::InitializeOnIOThread() {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
DCHECK(!Started());
SocketDescriptor socket_descriptor =
@@ -156,7 +158,7 @@ void EmbeddedTestServer::InitializeOnIOThread() {
}
void EmbeddedTestServer::ShutdownOnIOThread() {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
listen_socket_.reset();
STLDeleteContainerPairSecondPointers(connections_.begin(),
@@ -166,7 +168,7 @@ void EmbeddedTestServer::ShutdownOnIOThread() {
void EmbeddedTestServer::HandleRequest(HttpConnection* connection,
scoped_ptr<HttpRequest> request) {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
bool request_handled = false;
@@ -215,7 +217,7 @@ void EmbeddedTestServer::RegisterRequestHandler(
void EmbeddedTestServer::DidAccept(
StreamListenSocket* server,
scoped_ptr<StreamListenSocket> connection) {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
HttpConnection* http_connection = new HttpConnection(
connection.Pass(),
@@ -228,7 +230,7 @@ void EmbeddedTestServer::DidAccept(
void EmbeddedTestServer::DidRead(StreamListenSocket* connection,
const char* data,
int length) {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
HttpConnection* http_connection = FindConnection(connection);
if (http_connection == NULL) {
@@ -239,7 +241,7 @@ void EmbeddedTestServer::DidRead(StreamListenSocket* connection,
}
void EmbeddedTestServer::DidClose(StreamListenSocket* connection) {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
HttpConnection* http_connection = FindConnection(connection);
if (http_connection == NULL) {
@@ -252,7 +254,7 @@ void EmbeddedTestServer::DidClose(StreamListenSocket* connection) {
HttpConnection* EmbeddedTestServer::FindConnection(
StreamListenSocket* socket) {
- DCHECK(io_thread_->BelongsToCurrentThread());
+ DCHECK(io_thread_.message_loop_proxy()->BelongsToCurrentThread());
std::map<StreamListenSocket*, HttpConnection*>::iterator it =
connections_.find(socket);
@@ -277,8 +279,10 @@ bool EmbeddedTestServer::PostTaskToIOThreadAndWait(
temporary_loop.reset(new base::MessageLoop());
base::RunLoop run_loop;
- if (!io_thread_->PostTaskAndReply(FROM_HERE, closure, run_loop.QuitClosure()))
+ if (!io_thread_.message_loop_proxy()->PostTaskAndReply(
+ FROM_HERE, closure, run_loop.QuitClosure())) {
return false;
+ }
run_loop.Run();
return true;
diff --git a/net/test/embedded_test_server/embedded_test_server.h b/net/test/embedded_test_server/embedded_test_server.h
index f8c1bb5..a419951 100644
--- a/net/test/embedded_test_server/embedded_test_server.h
+++ b/net/test/embedded_test_server/embedded_test_server.h
@@ -14,6 +14,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "net/socket/tcp_listen_socket.h"
#include "url/gurl.h"
@@ -81,11 +82,9 @@ class EmbeddedTestServer : public StreamListenSocket::Delegate {
typedef base::Callback<scoped_ptr<HttpResponse>(
const HttpRequest& request)> HandleRequestCallback;
- // Creates a http test server. |io_thread| is a task runner
- // with IO message loop, used as a backend thread.
- // InitializeAndWaitUntilReady() must be called to start the server.
- explicit EmbeddedTestServer(
- const scoped_refptr<base::SingleThreadTaskRunner>& io_thread);
+ // Creates a http test server. InitializeAndWaitUntilReady() must be called
+ // to start the server.
+ EmbeddedTestServer();
virtual ~EmbeddedTestServer();
// Initializes and waits until the server is ready to accept requests.
@@ -150,7 +149,7 @@ class EmbeddedTestServer : public StreamListenSocket::Delegate {
bool PostTaskToIOThreadAndWait(
const base::Closure& closure) WARN_UNUSED_RESULT;
- scoped_refptr<base::SingleThreadTaskRunner> io_thread_;
+ base::Thread io_thread_;
scoped_ptr<HttpListenSocket> listen_socket_;
int port_;
diff --git a/net/test/embedded_test_server/embedded_test_server_unittest.cc b/net/test/embedded_test_server/embedded_test_server_unittest.cc
index 2c00518..a9c2efb 100644
--- a/net/test/embedded_test_server/embedded_test_server_unittest.cc
+++ b/net/test/embedded_test_server/embedded_test_server_unittest.cc
@@ -57,7 +57,7 @@ class EmbeddedTestServerTest: public testing::Test,
request_context_getter_ = new TestURLRequestContextGetter(
io_thread_.message_loop_proxy());
- server_.reset(new EmbeddedTestServer(io_thread_.message_loop_proxy()));
+ server_.reset(new EmbeddedTestServer);
ASSERT_TRUE(server_->InitializeAndWaitUntilReady());
}
@@ -273,7 +273,7 @@ class EmbeddedTestServerThreadingTestDelegate
loop.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO));
// Create the test server instance.
- EmbeddedTestServer server(io_thread_runner);
+ EmbeddedTestServer server;
base::FilePath src_dir;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
ASSERT_TRUE(server.InitializeAndWaitUntilReady());