summaryrefslogtreecommitdiffstats
path: root/net/socket/tcp_pinger_unittest.cc
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 18:15:23 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 18:15:23 +0000
commit4ce0e74c4378f5421ca3b1a17eeba4b8d42afb34 (patch)
tree4939a16032ef049b86450ace658a32d55dde305f /net/socket/tcp_pinger_unittest.cc
parent9a039afdaf755b7f1468628a5a2c6cfe848ca235 (diff)
downloadchromium_src-4ce0e74c4378f5421ca3b1a17eeba4b8d42afb34.zip
chromium_src-4ce0e74c4378f5421ca3b1a17eeba4b8d42afb34.tar.gz
chromium_src-4ce0e74c4378f5421ca3b1a17eeba4b8d42afb34.tar.bz2
Wait on a pipe for the test server to start up
This should speed up testserver-based unit tests considerably and make them less flakey. R=agl,cpu,phajdan,wtc BUG=49680 TEST=net_unittests Review URL: http://codereview.chromium.org/3368012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60199 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/tcp_pinger_unittest.cc')
-rw-r--r--net/socket/tcp_pinger_unittest.cc99
1 files changed, 0 insertions, 99 deletions
diff --git a/net/socket/tcp_pinger_unittest.cc b/net/socket/tcp_pinger_unittest.cc
deleted file mode 100644
index 3662032..0000000
--- a/net/socket/tcp_pinger_unittest.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/ref_counted.h"
-#include "base/trace_event.h"
-#include "net/base/address_list.h"
-#include "net/base/host_resolver.h"
-#include "net/base/listen_socket.h"
-#include "net/base/net_errors.h"
-#include "net/base/winsock_init.h"
-#include "net/socket/tcp_client_socket.h"
-#include "net/socket/tcp_pinger.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/platform_test.h"
-
-class TCPPingerTest
- : public PlatformTest, public ListenSocket::ListenSocketDelegate {
- public:
- TCPPingerTest() : listen_port_(0) {
- }
-
- // Implement ListenSocketDelegate methods
- virtual void DidAccept(ListenSocket* server, ListenSocket* connection) {
- // This callback doesn't seem to happen
- // right away, so this handler may not be called at all
- // during connect-only tests.
- LOG(INFO) << "TCPPinger accepted connection";
- connected_sock_ = connection;
- }
- virtual void DidRead(ListenSocket*, const char* str, int len) {
- // Not really needed yet, as TCPPinger doesn't support Read
- connected_sock_->Send(std::string("HTTP/1.1 404 Not Found"), true);
- connected_sock_ = NULL;
- }
- virtual void DidClose(ListenSocket* sock) {}
-
- // Testcase hooks
- virtual void SetUp();
-
- protected:
- int listen_port_;
- scoped_refptr<ListenSocket> listen_sock_;
-
- private:
- scoped_refptr<ListenSocket> connected_sock_;
-};
-
-void TCPPingerTest::SetUp() {
- PlatformTest::SetUp();
-
- // Find a free port to listen on
- // Range of ports to listen on. Shouldn't need to try many.
- static const int kMinPort = 10100;
- static const int kMaxPort = 10200;
-#if defined(OS_WIN)
- net::EnsureWinsockInit();
-#endif
- for (listen_port_ = kMinPort; listen_port_ < kMaxPort; listen_port_++) {
- listen_sock_ = ListenSocket::Listen("127.0.0.1", listen_port_, this);
- if (listen_sock_.get()) break;
- }
- ASSERT_TRUE(listen_sock_.get() != NULL);
-}
-
-TEST_F(TCPPingerTest, Ping) {
- net::AddressList addr;
- scoped_refptr<net::HostResolver> resolver(
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
- NULL));
-
- net::HostResolver::RequestInfo info(
- net::HostPortPair("localhost", listen_port_));
- int rv = resolver->Resolve(info, &addr, NULL, NULL, net::BoundNetLog());
- EXPECT_EQ(rv, net::OK);
-
- net::TCPPinger pinger(addr);
- rv = pinger.Ping();
- EXPECT_EQ(rv, net::OK);
-}
-
-TEST_F(TCPPingerTest, PingFail) {
- net::AddressList addr;
- scoped_refptr<net::HostResolver> resolver(
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
- NULL));
-
- // "Kill" "server"
- listen_sock_ = NULL;
-
- net::HostResolver::RequestInfo info(
- net::HostPortPair("localhost", listen_port_));
- int rv = resolver->Resolve(info, &addr, NULL, NULL, net::BoundNetLog());
- EXPECT_EQ(rv, net::OK);
-
- net::TCPPinger pinger(addr);
- rv = pinger.Ping(base::TimeDelta::FromMilliseconds(100), 1);
- EXPECT_NE(rv, net::OK);
-}