Chromium Code Reviews

Side by Side Diff: net/test/test_server.cc

Issue 3368012: Wait on a pipe for the test server to start up (Closed)
Patch Set: Sigh. Rebase onto trunk. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « net/test/test_server.h ('k') | net/test/test_server_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/test/test_server.h" 5 #include "net/test/test_server.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_MACOSX) 13 #if defined(OS_MACOSX)
14 #include "net/base/x509_certificate.h" 14 #include "net/base/x509_certificate.h"
15 #endif 15 #endif
16 16
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/leak_annotations.h" 19 #include "base/leak_annotations.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
25 #include "net/base/cert_test_util.h" 25 #include "net/base/cert_test_util.h"
26 #include "net/base/host_port_pair.h" 26 #include "net/base/host_port_pair.h"
27 #include "net/base/host_resolver.h" 27 #include "net/base/host_resolver.h"
28 #include "net/base/test_completion_callback.h" 28 #include "net/base/test_completion_callback.h"
29 #include "net/socket/tcp_client_socket.h" 29 #include "net/socket/tcp_client_socket.h"
30 #include "net/socket/tcp_pinger.h"
31 #include "net/test/python_utils.h" 30 #include "net/test/python_utils.h"
32 #include "testing/platform_test.h" 31 #include "testing/platform_test.h"
33 32
34 namespace { 33 namespace {
35 34
36 // Number of connection attempts for tests. 35 // Number of connection attempts for tests.
37 const int kServerConnectionAttempts = 10; 36 const int kServerConnectionAttempts = 10;
38 37
39 // Connection timeout in milliseconds for tests. 38 // Connection timeout in milliseconds for tests.
40 const int kServerConnectionTimeoutMs = 1000; 39 const int kServerConnectionTimeoutMs = 1000;
(...skipping 208 matching lines...)
249 LOG(ERROR) << "Failed to get DIR_EXE"; 248 LOG(ERROR) << "Failed to get DIR_EXE";
250 return false; 249 return false;
251 } 250 }
252 generated_code_dir = generated_code_dir.Append(FILE_PATH_LITERAL("pyproto")); 251 generated_code_dir = generated_code_dir.Append(FILE_PATH_LITERAL("pyproto"));
253 AppendToPythonPath(generated_code_dir); 252 AppendToPythonPath(generated_code_dir);
254 AppendToPythonPath(generated_code_dir.Append(FILE_PATH_LITERAL("sync_pb"))); 253 AppendToPythonPath(generated_code_dir.Append(FILE_PATH_LITERAL("sync_pb")));
255 254
256 return true; 255 return true;
257 } 256 }
258 257
259 bool TestServer::WaitToStart() {
260 net::AddressList addr;
261 if (!GetAddressList(&addr))
262 return false;
263
264 net::TCPPinger pinger(addr);
265 int rv = pinger.Ping(
266 base::TimeDelta::FromMilliseconds(kServerConnectionTimeoutMs),
267 kServerConnectionAttempts);
268 bool result = (rv == net::OK);
269 if (!result) {
270 LOG(ERROR) << "Failed to connect to server";
271 }
272 return result;
273 }
274
275 FilePath TestServer::GetRootCertificatePath() { 258 FilePath TestServer::GetRootCertificatePath() {
276 return certificates_dir_.AppendASCII("root_ca_cert.crt"); 259 return certificates_dir_.AppendASCII("root_ca_cert.crt");
277 } 260 }
278 261
279 bool TestServer::LoadTestRootCert() { 262 bool TestServer::LoadTestRootCert() {
280 #if defined(USE_NSS) 263 #if defined(USE_NSS)
281 if (cert_) 264 if (cert_)
282 return true; 265 return true;
283 266
284 // TODO(dkegel): figure out how to get this to only happen once? 267 // TODO(dkegel): figure out how to get this to only happen once?
(...skipping 26 matching lines...)
311 return certificates_dir_.AppendASCII("ok_cert.pem"); 294 return certificates_dir_.AppendASCII("ok_cert.pem");
312 case TYPE_HTTPS_EXPIRED_CERTIFICATE: 295 case TYPE_HTTPS_EXPIRED_CERTIFICATE:
313 return certificates_dir_.AppendASCII("expired_cert.pem"); 296 return certificates_dir_.AppendASCII("expired_cert.pem");
314 default: 297 default:
315 NOTREACHED(); 298 NOTREACHED();
316 } 299 }
317 return FilePath(); 300 return FilePath();
318 } 301 }
319 302
320 } // namespace net 303 } // namespace net
OLDNEW
« no previous file with comments | « net/test/test_server.h ('k') | net/test/test_server_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine