diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 21:00:18 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 21:00:18 +0000 |
commit | c0d297956354b9c74fdcfb717efb272a772f4315 (patch) | |
tree | 94beb2ca93a6e9ad36952c6ef163f67f3da58b1e | |
parent | 5d8128106e8bae8784d9468706198c61c505641b (diff) | |
download | chromium_src-c0d297956354b9c74fdcfb717efb272a772f4315.zip chromium_src-c0d297956354b9c74fdcfb717efb272a772f4315.tar.gz chromium_src-c0d297956354b9c74fdcfb717efb272a772f4315.tar.bz2 |
linux: expose the ProcessSingleton timeout to speed tests
We have a 20-second timeout normally, but for testing purposes 1 second is
plenty.
Review URL: http://codereview.chromium.org/209018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26483 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/process_singleton.h | 7 | ||||
-rw-r--r-- | chrome/browser/process_singleton_linux.cc | 9 | ||||
-rw-r--r-- | chrome/browser/process_singleton_linux_uitest.cc | 4 |
3 files changed, 17 insertions, 3 deletions
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h index 122618f..e06a7e8 100644 --- a/chrome/browser/process_singleton.h +++ b/chrome/browser/process_singleton.h @@ -40,6 +40,7 @@ class ProcessSingleton : public NonThreadSafe { explicit ProcessSingleton(const FilePath& user_data_dir); ~ProcessSingleton(); + // Notify another process, if available. // Returns true if another process was found and notified, false if we // should continue with this process. // Windows code roughly based on Mozilla. @@ -49,6 +50,12 @@ class ProcessSingleton : public NonThreadSafe { // first one, so this function won't find it. NotifyResult NotifyOtherProcess(); +#if defined(OS_LINUX) + // Exposed for testing. We use a timeout on Linux, and in tests we want + // this timeout to be short. + NotifyResult NotifyOtherProcessWithTimeout(int timeout_seconds); +#endif + // Sets ourself up as the singleton instance. void Create(); diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc index db2d31d..634b68f 100644 --- a/chrome/browser/process_singleton_linux.cc +++ b/chrome/browser/process_singleton_linux.cc @@ -627,6 +627,11 @@ ProcessSingleton::~ProcessSingleton() { } ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { + return NotifyOtherProcessWithTimeout(kTimeoutInSeconds); +} + +ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout( + int timeout_seconds) { int socket; sockaddr_un addr; SetupSocket(socket_path_.value(), &socket, &addr); @@ -648,7 +653,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { return PROCESS_NONE; // Tell the caller there's nobody to notify. } - timeval timeout = {20, 0}; + timeval timeout = {timeout_seconds, 0}; setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); // Found another process, prepare our command line @@ -684,7 +689,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { // timeout, to make sure the other process has enough time to return ACK. char buf[kMaxACKMessageLength + 1]; ssize_t len = - ReadFromSocket(socket, buf, kMaxACKMessageLength, kTimeoutInSeconds); + ReadFromSocket(socket, buf, kMaxACKMessageLength, timeout_seconds); // Failed to read ACK, the other process might have been frozen. if (len <= 0) { diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc index 6119e3d..d7f309a 100644 --- a/chrome/browser/process_singleton_linux_uitest.cc +++ b/chrome/browser/process_singleton_linux_uitest.cc @@ -58,7 +58,9 @@ class ProcessSingletonLinuxTest : public UITest { ProcessSingleton process_singleton(user_data_dir); - return process_singleton.NotifyOtherProcess(); + // Use a short timeout to keep tests fast. + const int kTimeoutSeconds = 3; + return process_singleton.NotifyOtherProcessWithTimeout(kTimeoutSeconds); } std::vector<std::string> old_argv_; |