Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: chrome/browser/process_singleton_posix_unittest.cc

Issue 2871793003: Added histograms on process singleton create when remote process exists and we cannot notify it (Closed)
Patch Set: Some fixes basing on review comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/process_singleton.h" 5 #include "chrome/browser/process_singleton.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <limits.h> 8 #include <limits.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 #include <sys/un.h> 12 #include <sys/un.h>
13 #include <sys/wait.h> 13 #include <sys/wait.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include <memory> 16 #include <memory>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/bind.h" 20 #include "base/bind.h"
21 #include "base/command_line.h" 21 #include "base/command_line.h"
22 #include "base/files/file_path.h" 22 #include "base/files/file_path.h"
23 #include "base/files/file_util.h" 23 #include "base/files/file_util.h"
24 #include "base/files/scoped_temp_dir.h" 24 #include "base/files/scoped_temp_dir.h"
25 #include "base/location.h" 25 #include "base/location.h"
26 #include "base/posix/eintr_wrapper.h" 26 #include "base/posix/eintr_wrapper.h"
27 #include "base/single_thread_task_runner.h" 27 #include "base/single_thread_task_runner.h"
28 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
29 #include "base/synchronization/waitable_event.h" 29 #include "base/synchronization/waitable_event.h"
30 #include "base/test/histogram_tester.h"
30 #include "base/test/test_timeouts.h" 31 #include "base/test/test_timeouts.h"
31 #include "base/test/thread_test_helper.h" 32 #include "base/test/thread_test_helper.h"
32 #include "base/threading/thread.h" 33 #include "base/threading/thread.h"
33 #include "build/build_config.h" 34 #include "build/build_config.h"
34 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "content/public/test/test_browser_thread_bundle.h" 37 #include "content/public/test/test_browser_thread_bundle.h"
37 #include "net/base/network_interfaces.h" 38 #include "net/base/network_interfaces.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 40
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // TODO(james.su@gmail.com): port following tests to Windows. 280 // TODO(james.su@gmail.com): port following tests to Windows.
280 // Test success case of NotifyOtherProcess(). 281 // Test success case of NotifyOtherProcess().
281 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessSuccess) { 282 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessSuccess) {
282 CreateProcessSingletonOnThread(); 283 CreateProcessSingletonOnThread();
283 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, NotifyOtherProcess(true)); 284 EXPECT_EQ(ProcessSingleton::PROCESS_NOTIFIED, NotifyOtherProcess(true));
284 CheckNotified(); 285 CheckNotified();
285 } 286 }
286 287
287 // Test failure case of NotifyOtherProcess(). 288 // Test failure case of NotifyOtherProcess().
288 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessFailure) { 289 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessFailure) {
290 base::HistogramTester histogram_tester;
289 CreateProcessSingletonOnThread(); 291 CreateProcessSingletonOnThread();
290 292
291 BlockWorkerThread(); 293 BlockWorkerThread();
292 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, NotifyOtherProcess(true)); 294 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, NotifyOtherProcess(true));
293 ASSERT_EQ(1, kill_callbacks_); 295 ASSERT_EQ(1, kill_callbacks_);
294 UnblockWorkerThread(); 296 UnblockWorkerThread();
297 histogram_tester.ExpectUniqueSample(
298 "Chrome.ProcessSingleton.RemoteHungProcessTerminateReason",
299 ProcessSingleton::SOCKET_READ_FAILED, 1u);
295 } 300 }
296 301
297 // Test that we don't kill ourselves by accident if a lockfile with the same pid 302 // Test that we don't kill ourselves by accident if a lockfile with the same pid
298 // happens to exist. 303 // happens to exist.
299 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessNoSuicide) { 304 TEST_F(ProcessSingletonPosixTest, NotifyOtherProcessNoSuicide) {
300 CreateProcessSingletonOnThread(); 305 CreateProcessSingletonOnThread();
301 // Replace lockfile with one containing our own pid. 306 // Replace lockfile with one containing our own pid.
302 EXPECT_EQ(0, unlink(lock_path_.value().c_str())); 307 EXPECT_EQ(0, unlink(lock_path_.value().c_str()));
303 std::string symlink_content = base::StringPrintf( 308 std::string symlink_content = base::StringPrintf(
304 "%s%c%u", 309 "%s%c%u",
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Test that if there is an existing lock file, and it's not locked, we replace 449 // Test that if there is an existing lock file, and it's not locked, we replace
445 // it. 450 // it.
446 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) { 451 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) {
447 std::unique_ptr<TestableProcessSingleton> process_singleton( 452 std::unique_ptr<TestableProcessSingleton> process_singleton(
448 CreateProcessSingleton()); 453 CreateProcessSingleton());
449 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0)); 454 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0));
450 EXPECT_TRUE(process_singleton->Create()); 455 EXPECT_TRUE(process_singleton->Create());
451 VerifyFiles(); 456 VerifyFiles();
452 } 457 }
453 #endif // defined(OS_MACOSX) 458 #endif // defined(OS_MACOSX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698