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

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

Issue 2733323002: Changing multiprocess test SpawnChild to return a struct. (Closed)
Patch Set: Synced Created 3 years, 9 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 "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
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_child =
58 ASSERT_TRUE(process.IsValid()); 58 SpawnChild("MultiProcessLockTryFailMain");
59 ASSERT_TRUE(spawn_child.process.IsValid());
59 int exit_code = -1; 60 int exit_code = -1;
60 EXPECT_TRUE(process.WaitForExit(&exit_code)); 61 EXPECT_TRUE(spawn_child.process.WaitForExit(&exit_code));
61 EXPECT_EQ(0, exit_code); 62 EXPECT_EQ(0, exit_code);
62 } 63 }
63 64
64 void MultiProcessLockTest::ExpectLockIsUnlocked( 65 void MultiProcessLockTest::ExpectLockIsUnlocked(
65 const std::string &name) { 66 const std::string &name) {
66 ScopedEnvironmentVariable var(kLockEnviromentVarName, name); 67 ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
67 base::Process process = SpawnChild("MultiProcessLockTrySucceedMain"); 68 base::SpawnChildResult spawn_child =
68 ASSERT_TRUE(process.IsValid()); 69 SpawnChild("MultiProcessLockTrySucceedMain");
70 ASSERT_TRUE(spawn_child.process.IsValid());
69 int exit_code = -1; 71 int exit_code = -1;
70 EXPECT_TRUE(process.WaitForExit(&exit_code)); 72 EXPECT_TRUE(spawn_child.process.WaitForExit(&exit_code));
71 EXPECT_EQ(0, exit_code); 73 EXPECT_EQ(0, exit_code);
72 } 74 }
73 75
74 TEST_F(MultiProcessLockTest, BasicCreationTest) { 76 TEST_F(MultiProcessLockTest, BasicCreationTest) {
75 // Test basic creation/destruction with no lock taken 77 // Test basic creation/destruction with no lock taken
76 std::string name = GenerateLockName(); 78 std::string name = GenerateLockName();
77 std::unique_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name)); 79 std::unique_ptr<MultiProcessLock> scoped(MultiProcessLock::Create(name));
78 ExpectLockIsUnlocked(name); 80 ExpectLockIsUnlocked(name);
79 scoped.reset(NULL); 81 scoped.reset(NULL);
80 } 82 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 std::unique_ptr<base::Environment> environment(base::Environment::Create()); 171 std::unique_ptr<base::Environment> environment(base::Environment::Create());
170 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName, 172 EXPECT_TRUE(environment->GetVar(MultiProcessLockTest::kLockEnviromentVarName,
171 &name)); 173 &name));
172 std::unique_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name)); 174 std::unique_ptr<MultiProcessLock> test_lock(MultiProcessLock::Create(name));
173 175
174 // Expect locking to succeed because it is not claimed yet. 176 // Expect locking to succeed because it is not claimed yet.
175 bool locked_successfully = test_lock->TryLock(); 177 bool locked_successfully = test_lock->TryLock();
176 EXPECT_TRUE(locked_successfully); 178 EXPECT_TRUE(locked_successfully);
177 return !locked_successfully; 179 return !locked_successfully;
178 } 180 }
OLDNEW
« no previous file with comments | « chrome/common/component_flash_hint_file_linux_unittest.cc ('k') | chrome/common/service_process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698