OLD | NEW |
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 "chrome/common/multi_process_lock.h" | 5 #include "chrome/common/multi_process_lock.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 = "MULTI_PROCESS_TEST_LOCK_NAME"; | 47 = "MULTI_PROCESS_TEST_LOCK_NAME"; |
48 | 48 |
49 std::string MultiProcessLockTest::GenerateLockName() { | 49 std::string MultiProcessLockTest::GenerateLockName() { |
50 base::Time now = base::Time::NowFromSystemTime(); | 50 base::Time now = base::Time::NowFromSystemTime(); |
51 return base::StringPrintf("multi_process_test_lock %lf%lf", | 51 return base::StringPrintf("multi_process_test_lock %lf%lf", |
52 now.ToDoubleT(), base::RandDouble()); | 52 now.ToDoubleT(), base::RandDouble()); |
53 } | 53 } |
54 | 54 |
55 void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) { | 55 void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) { |
56 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); | 56 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); |
57 base::Process process = SpawnChild("MultiProcessLockTryFailMain"); | 57 base::SpawnChildResult spawn_result = |
| 58 SpawnChild("MultiProcessLockTryFailMain"); |
| 59 base::Process process = std::move(spawn_result.process); |
58 ASSERT_TRUE(process.IsValid()); | 60 ASSERT_TRUE(process.IsValid()); |
59 int exit_code = -1; | 61 int exit_code = -1; |
60 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 62 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
61 EXPECT_EQ(0, exit_code); | 63 EXPECT_EQ(0, exit_code); |
62 } | 64 } |
63 | 65 |
64 void MultiProcessLockTest::ExpectLockIsUnlocked( | 66 void MultiProcessLockTest::ExpectLockIsUnlocked( |
65 const std::string &name) { | 67 const std::string &name) { |
66 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); | 68 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); |
67 base::Process process = SpawnChild("MultiProcessLockTrySucceedMain"); | 69 base::SpawnChildResult spawn_result = |
| 70 SpawnChild("MultiProcessLockTrySucceedMain"); |
| 71 base::Process process = std::move(spawn_result.process); |
68 ASSERT_TRUE(process.IsValid()); | 72 ASSERT_TRUE(process.IsValid()); |
69 int exit_code = -1; | 73 int exit_code = -1; |
70 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 74 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
71 EXPECT_EQ(0, exit_code); | 75 EXPECT_EQ(0, exit_code); |
72 } | 76 } |
73 | 77 |
74 TEST_F(MultiProcessLockTest, BasicCreationTest) { | 78 TEST_F(MultiProcessLockTest, BasicCreationTest) { |
75 // Test basic creation/destruction with no lock taken | 79 // Test basic creation/destruction with no lock taken |
76 std::string name = GenerateLockName(); | 80 std::string name = GenerateLockName(); |
77 std::unique_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); | 81 std::unique_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 std::unique_ptr<base::Environment> environment(base::Environment::Create()); | 173 std::unique_ptr<base::Environment> environment(base::Environment::Create()); |
170 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, | 174 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, |
171 &name)); | 175 &name)); |
172 std::unique_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); | 176 std::unique_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); |
173 | 177 |
174 // Expect locking to succeed because it is not claimed yet. | 178 // Expect locking to succeed because it is not claimed yet. |
175 bool locked_successfully = test_lock->TryLock(); | 179 bool locked_successfully = test_lock->TryLock(); |
176 EXPECT_TRUE(locked_successfully); | 180 EXPECT_TRUE(locked_successfully); |
177 return !locked_successfully; | 181 return !locked_successfully; |
178 } | 182 } |
OLD | NEW |