summaryrefslogtreecommitdiffstats
path: root/net/test
diff options
context:
space:
mode:
authorrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 23:41:04 +0000
committerrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 23:41:04 +0000
commitc47d81dedaf59d3441acdc0cd60fdddc7078aa2d (patch)
treea9b24dddc91774e3ce9ef212807a5fb406d1b295 /net/test
parent23f5ee3f8b0c9f854c080db48b1f97603576d865 (diff)
downloadchromium_src-c47d81dedaf59d3441acdc0cd60fdddc7078aa2d.zip
chromium_src-c47d81dedaf59d3441acdc0cd60fdddc7078aa2d.tar.gz
chromium_src-c47d81dedaf59d3441acdc0cd60fdddc7078aa2d.tar.bz2
Clean up orphaned testserver processes before launching a new one in net::TestServer
Several chrome tests have failed in recent days because some test cases crashed due to failures, leaving behind orphaned testserver processes. These test suites do not use out_of_proc_test_runner, and therefore, do not get the benefit of using the LaunchAppInNewProcessGroup()/KillProcessGroup() mechanism. This patch implements an added layer of safety, by causing TestServer::LaunchPython() to first kill any remaining orphaned instances of testserver.py before launching a new one. The check for an orphaned testserver process on POSIX is a process with exe_name "python", a parent_pid of "1" (indicating that it's an orphan), and command line parameters that contain the strings "testserver.py" and "<port>" where <port> is the port that is being used by the test server instance. BUG=55808,57253 TEST=Run a test that spawns a testserver and dies. Run another test. It shouldn't fail. Review URL: http://codereview.chromium.org/3537002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r--net/test/test_server_posix.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/net/test/test_server_posix.cc b/net/test/test_server_posix.cc
index 262845c..6e65bcf 100644
--- a/net/test/test_server_posix.cc
+++ b/net/test/test_server_posix.cc
@@ -4,9 +4,52 @@
#include "net/test/test_server.h"
+#include <vector>
+
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/process_util.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
+
+namespace {
+
+// Helper class used to detect and kill orphaned python test server processes.
+// Checks if the command line of a process contains |path_string| (the path
+// from which the test server was launched) and |port_string| (the port used by
+// the test server), and if the parent pid of the process is 1 (indicating that
+// it is an orphaned process).
+class OrphanedTestServerFilter : public base::ProcessFilter {
+ public:
+ OrphanedTestServerFilter(
+ const std::string& path_string, const std::string& port_string)
+ : path_string_(path_string),
+ port_string_(port_string) {}
+
+ virtual bool Includes(const base::ProcessEntry& entry) const {
+ if (entry.parent_pid() != 1)
+ return false;
+ bool found_path_string = false;
+ bool found_port_string = false;
+ for (std::vector<std::string>::const_iterator it =
+ entry.cmd_line_args().begin();
+ it != entry.cmd_line_args().end();
+ ++it) {
+ if (it->find(path_string_) != std::string::npos)
+ found_path_string = true;
+ if (it->find(port_string_) != std::string::npos)
+ found_port_string = true;
+ }
+ return found_path_string && found_port_string;
+ }
+
+ private:
+ std::string path_string_;
+ std::string port_string_;
+ DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter);
+};
+
+} // namespace
namespace net {
bool TestServer::LaunchPython(const FilePath& testserver_path) {
@@ -47,6 +90,14 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) {
command_line.push_back("--startup-pipe=" + base::IntToString(pipefd[1]));
+ // Try to kill any orphaned testserver processes that may be running.
+ OrphanedTestServerFilter filter(testserver_path.value(),
+ base::IntToString(host_port_pair_.port()));
+ if (!base::KillProcesses(L"python", -1, &filter)) {
+ LOG(WARNING) << "Failed to clean up older orphaned testserver instances.";
+ }
+
+ // Launch a new testserver process.
if (!base::LaunchApp(command_line, map_write_fd, false, &process_handle_)) {
LOG(ERROR) << "Failed to launch " << command_line[0] << " ...";
return false;