summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 20:55:41 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 20:55:41 +0000
commit1ed7e00c6e9d9b757117ca51c652a5460b5b8d66 (patch)
treed74cdce03e2b492049e12c95486763d20bf71ea9 /net
parent1b14b48c15ebf03c46463d974cb2049e2c2f52e9 (diff)
downloadchromium_src-1ed7e00c6e9d9b757117ca51c652a5460b5b8d66.zip
chromium_src-1ed7e00c6e9d9b757117ca51c652a5460b5b8d66.tar.gz
chromium_src-1ed7e00c6e9d9b757117ca51c652a5460b5b8d66.tar.bz2
Can wait for testserver python process to exit.
This exit could be initiated by the JScript code in a test page notifying us that the test is finished it's time to get the results (saved in server's 'dump' directory). Review URL: http://codereview.chromium.org/21090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/url_request/url_request_unittest.h42
1 files changed, 27 insertions, 15 deletions
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index 9a71e5f..152d85e 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -200,8 +200,7 @@ class TestDelegate : public URLRequest::Delegate {
// This object bounds the lifetime of an external python-based HTTP/FTP server
// that can provide various responses useful for testing.
-class BaseTestServer : public base::ProcessFilter,
- public base::RefCounted<BaseTestServer> {
+class BaseTestServer : public base::RefCounted<BaseTestServer> {
protected:
BaseTestServer()
: process_handle_(NULL) {
@@ -209,9 +208,16 @@ class BaseTestServer : public base::ProcessFilter,
public:
virtual ~BaseTestServer() {
+ if (process_handle_)
+ if (!WaitToFinish(1000))
+ Kill();
+ }
+
+ void Kill() {
if (process_handle_) {
#if defined(OS_WIN)
- CloseHandle(process_handle_);
+ base::KillProcess(process_handle_, 0, true);
+ ::CloseHandle(process_handle_);
#elif defined(OS_POSIX)
// Make sure the process has exited and clean up the process to avoid
// a zombie.
@@ -220,20 +226,18 @@ class BaseTestServer : public base::ProcessFilter,
#endif
process_handle_ = NULL;
}
- // Make sure we don't leave any stray testserver processes laying around.
- std::wstring testserver_name =
- file_util::GetFilenameFromPath(python_runtime_);
- base::CleanupProcesses(testserver_name, 10000, 1, this);
- EXPECT_EQ(0, base::GetProcessCount(testserver_name, this));
}
- // Implementation of ProcessFilter
- virtual bool Includes(uint32 pid, uint32 parent_pid) const {
- // Since no process handle is set, it can't be included in the filter.
- if (!process_handle_)
- return false;
- // TODO(port): rationalize return value of GetProcId
- return pid == static_cast<uint32>(base::GetProcId(process_handle_));
+ bool WaitToFinish(int milliseconds) {
+ bool ret = base::WaitForSingleProcess(process_handle_, milliseconds);
+ if (ret) {
+#if defined(OS_WIN)
+ ::CloseHandle(process_handle_);
+#endif
+ process_handle_ = NULL;
+ }
+
+ return ret;
}
GURL TestServerPage(const std::string& base_address,
@@ -495,6 +499,10 @@ class HTTPTestServer : public BaseTestServer {
}
virtual ~HTTPTestServer() {
+ Stop();
+ }
+
+ void Stop() {
// here we append the time to avoid problems where the kill page
// is being cached rather than being executed on the server
std::string page_name = StringPrintf("kill?%u",
@@ -653,6 +661,10 @@ class FTPTestServer : public BaseTestServer {
}
virtual ~FTPTestServer() {
+ Stop();
+ }
+
+ void Stop() {
const std::string base_address = scheme() + "://" + host_name_ + ":" +
port_str_ + "/";
const GURL& url = TestServerPage(base_address, "kill");