diff options
Diffstat (limited to 'net/url_request/url_request_unittest.h')
-rw-r--r-- | net/url_request/url_request_unittest.h | 42 |
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"); |