From b5f95100c3fb57469f24a2dc7feb62b41c8f5098 Mon Sep 17 00:00:00 2001 From: "jcampan@chromium.org" Date: Wed, 1 Jul 2009 19:53:59 +0000 Subject: Adds time-out to browser-tests to prevent a hanging test from hanging the entire test suite. Bug=None TEST=None Review URL: http://codereview.chromium.org/151158 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19755 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/test/in_process_browser_test.cc | 25 +++++++++++++++++++++++++ chrome/test/in_process_browser_test.h | 3 +++ 2 files changed, 28 insertions(+) (limited to 'chrome/test') diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index 64007de..e698e27 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -33,6 +33,13 @@ extern int BrowserMain(const MainFunctionParams&); const wchar_t kUnitTestShowWindows[] = L"show-windows"; +// Delay for the time-out at which we stop the inner-message loop the first +// time. +const int kInitialTimeoutInMS = 30000; + +// Delay for sub-sequent time-outs once the initial time-out happened. +const int kSubsequentTimeoutInMS = 5000; + namespace { bool DieFileDie(const std::wstring& file, bool recurse) { @@ -205,6 +212,11 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { browser_ = CreateBrowser(profile); + // Start the timeout timer to prevent hangs. + MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, + NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), + kInitialTimeoutInMS); + RunTestOnMainThread(); BrowserList::const_iterator browser = BrowserList::begin(); @@ -224,3 +236,16 @@ void InProcessBrowserTest::ConfigureHostMapper( // We don't want the test code to use it. host_mapper->AddSimulatedFailure("wpad"); } + +void InProcessBrowserTest::TimedOut() { + DCHECK(MessageLoopForUI::current()->IsNested()); + + GTEST_NONFATAL_FAILURE_("Timed-out"); + + // Start the timeout timer to prevent hangs. + MessageLoopForUI::current()->PostDelayedTask(FROM_HERE, + NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), + kSubsequentTimeoutInMS); + + MessageLoopForUI::current()->Quit(); +} diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h index 7795c8a..27f5bff 100644 --- a/chrome/test/in_process_browser_test.h +++ b/chrome/test/in_process_browser_test.h @@ -67,6 +67,9 @@ class InProcessBrowserTest : public testing::Test { // do that during testing. virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper); + // Invoked when a test is not finishing in a timely manner. + void TimedOut(); + // Starts an HTTP server. HTTPTestServer* StartHTTPServer(); -- cgit v1.1