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

Side by Side Diff: chrome/common/multi_process_lock_unittest.cc

Issue 843113003: MultiProcessTest: Update SpawnChild* to return a Process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/process/kill.h" 9 #include "base/process/kill.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 = "MULTI_PROCESS_TEST_LOCK_NAME"; 44 = "MULTI_PROCESS_TEST_LOCK_NAME";
45 45
46 std::string MultiProcessLockTest::GenerateLockName() { 46 std::string MultiProcessLockTest::GenerateLockName() {
47 base::Time now = base::Time::NowFromSystemTime(); 47 base::Time now = base::Time::NowFromSystemTime();
48 return base::StringPrintf("multi_process_test_lock %lf%lf", 48 return base::StringPrintf("multi_process_test_lock %lf%lf",
49 now.ToDoubleT(), base::RandDouble()); 49 now.ToDoubleT(), base::RandDouble());
50 } 50 }
51 51
52 void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) { 52 void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) {
53 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); 53 ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
54 base::ProcessHandle handle = SpawnChild("MultiProcessLockTryFailMain"); 54 base::Process process = SpawnChild("MultiProcessLockTryFailMain");
55 ASSERT_TRUE(handle); 55 ASSERT_TRUE(process.IsValid());
56 int exit_code = 0; 56 int exit_code = 0;
57 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); 57 EXPECT_TRUE(process.WaitForExit(&exit_code));
58 EXPECT_EQ(exit_code, 0); 58 EXPECT_EQ(exit_code, 0);
59 } 59 }
60 60
61 void MultiProcessLockTest::ExpectLockIsUnlocked( 61 void MultiProcessLockTest::ExpectLockIsUnlocked(
62 const std::string &name) { 62 const std::string &name) {
63 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); 63 ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
64 base::ProcessHandle handle = SpawnChild("MultiProcessLockTrySucceedMain"); 64 base::Process process = SpawnChild("MultiProcessLockTrySucceedMain");
65 ASSERT_TRUE(handle); 65 ASSERT_TRUE(process.IsValid());
66 int exit_code = 0; 66 int exit_code = 0;
67 EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); 67 EXPECT_TRUE(process.WaitForExit(&exit_code));
68 EXPECT_EQ(exit_code, 0); 68 EXPECT_EQ(exit_code, 0);
69 } 69 }
70 70
71 TEST_F(MultiProcessLockTest, BasicCreationTest) { 71 TEST_F(MultiProcessLockTest, BasicCreationTest) {
72 // Test basic creation/destruction with no lock taken 72 // Test basic creation/destruction with no lock taken
73 std::string name = GenerateLockName(); 73 std::string name = GenerateLockName();
74 scoped_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); 74 scoped_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name));
75 ExpectLockIsUnlocked(name); 75 ExpectLockIsUnlocked(name);
76 scoped.reset(NULL); 76 scoped.reset(NULL);
77 } 77 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 MULTIPROCESS_TEST_MAIN(MultiProcessLockTrySucceedMain) { 162 MULTIPROCESS_TEST_MAIN(MultiProcessLockTrySucceedMain) {
163 std::string name; 163 std::string name;
164 scoped_ptr<base::Environment> environment(base::Environment::Create()); 164 scoped_ptr<base::Environment> environment(base::Environment::Create());
165 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, 165 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName,
166 &name)); 166 &name));
167 scoped_ptr<MultiProcessLock> test_lock( 167 scoped_ptr<MultiProcessLock> test_lock(
168 MultiProcessLock::Create(name)); 168 MultiProcessLock::Create(name));
169 EXPECT_TRUE(test_lock->TryLock()); 169 EXPECT_TRUE(test_lock->TryLock());
170 return 0; 170 return 0;
171 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698