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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java

Issue 704573002: Android: Use a spawning queue for child processes while we are at capacity. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on master. Created 6 years 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.RemoteException; 8 import android.os.RemoteException;
9 import android.test.InstrumentationTestCase; 9 import android.test.InstrumentationTestCase;
10 import android.test.suitebuilder.annotation.MediumTest; 10 import android.test.suitebuilder.annotation.MediumTest;
11 11
12 import org.chromium.base.library_loader.LibraryLoader; 12 import org.chromium.base.library_loader.LibraryLoader;
13 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.test.util.Criteria; 14 import org.chromium.content.browser.test.util.Criteria;
15 import org.chromium.content.browser.test.util.CriteriaHelper; 15 import org.chromium.content.browser.test.util.CriteriaHelper;
16 16
17 /** 17 /**
18 * Instrumentation tests for ChildProcessLauncher. 18 * Instrumentation tests for ChildProcessLauncher.
19 */ 19 */
20 public class ChildProcessLauncherTest extends InstrumentationTestCase { 20 public class ChildProcessLauncherTest extends InstrumentationTestCase {
21 /** 21 /**
22 * Tests cleanup for a connection that fails to connect in the first place. 22 * Tests cleanup for a connection that fails to connect in the first place.
23 */ 23 */
24 @MediumTest 24 @MediumTest
25 @Feature({"ProcessManagement"}) 25 @Feature({"ProcessManagement"})
26 public void testServiceFailedToBind() throws InterruptedException, RemoteExc eption { 26 public void testServiceFailedToBind() throws InterruptedException, RemoteExc eption {
27 Context appContext = getInstrumentation().getTargetContext(); 27 final Context appContext = getInstrumentation().getTargetContext();
28 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext)); 28 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext));
29 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()) ; 29 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()) ;
30 30
31 // Try to allocate a connection to service class in incorrect package. W e can do that by 31 // Try to allocate a connection to service class in incorrect package. W e can do that by
32 // using the instrumentation context (getContext()) instead of the app c ontext 32 // using the instrumentation context (getContext()) instead of the app c ontext
33 // (getTargetContext()). 33 // (getTargetContext()).
34 Context context = getInstrumentation().getContext(); 34 Context context = getInstrumentation().getContext();
35 ChildProcessLauncher.allocateBoundConnectionForTesting(context); 35 ChildProcessLauncher.allocateBoundConnectionForTesting(context);
36 36
37 // Verify that the connection is not considered as allocated. 37 // Verify that the connection is not considered as allocated.
38 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext)); 38 assertTrue("Crashed connection wasn't released from the allocator.",
39 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()) ; 39 CriteriaHelper.pollForCriteria(new Criteria() {
40 @Override
41 public boolean isSatisfied() {
42 return ChildProcessLauncher.allocatedConnectionsCountFor Testing(
ppi 2014/12/19 12:28:52 To reliably ensure that the connection was not all
auygun 2014/12/19 13:18:17 Sure. I'll also change the assert below. It doesn'
43 appContext) == 0;
44 }
45 }));
46
47 assertTrue("Crashed connection wasn't released from ChildProcessLauncher .",
48 CriteriaHelper.pollForCriteria(new Criteria() {
49 @Override
50 public boolean isSatisfied() {
51 return ChildProcessLauncher.connectedServicesCountForTes ting() == 0;
52 }
53 }));
40 } 54 }
41 55
42 /** 56 /**
43 * Tests cleanup for a connection that terminates before setup. 57 * Tests cleanup for a connection that terminates before setup.
44 */ 58 */
45 @MediumTest 59 @MediumTest
46 @Feature({"ProcessManagement"}) 60 @Feature({"ProcessManagement"})
47 public void testServiceCrashedBeforeSetup() throws InterruptedException, Rem oteException { 61 public void testServiceCrashedBeforeSetup() throws InterruptedException, Rem oteException {
48 final Context appContext = getInstrumentation().getTargetContext(); 62 final Context appContext = getInstrumentation().getTargetContext();
49 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext)); 63 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 @Override 145 @Override
132 public boolean isSatisfied() { 146 public boolean isSatisfied() {
133 return ChildProcessLauncher.connectedServicesCountForTes ting() == 0; 147 return ChildProcessLauncher.connectedServicesCountForTes ting() == 0;
134 } 148 }
135 })); 149 }));
136 150
137 // Verify that the connection pid remains set after termination. 151 // Verify that the connection pid remains set after termination.
138 assertTrue(connection.getPid() != 0); 152 assertTrue(connection.getPid() != 0);
139 } 153 }
140 154
155 /**
156 * Tests spawning a pending process from queue.
157 */
158 @MediumTest
159 @Feature({"ProcessManagement"})
160 public void testPendingSpawnQueue() throws InterruptedException, RemoteExcep tion {
161 final Context appContext = getInstrumentation().getTargetContext();
162 assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext));
163
164 // Start and connect to a new service.
165 final ChildProcessConnectionImpl connection = startConnection();
166 assertEquals(1, ChildProcessLauncher.allocatedConnectionsCountForTesting (appContext));
167
168 // Queue up a a new spawn request.
169 ChildProcessLauncher.enqueuePendingSpawnForTesting(appContext);
170 assertEquals(1, ChildProcessLauncher.pendingSpawnsCountForTesting());
171
172 // Initiate the connection setup.
173 ChildProcessLauncher.triggerConnectionSetup(connection, new String[0], 1 ,
174 new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_REN DERER_PROCESS, 0);
175
176 // Verify that the connection completes the setup.
177 assertTrue("The connection wasn't registered in ChildProcessLauncher aft er setup.",
178 CriteriaHelper.pollForCriteria(new Criteria() {
179 @Override
180 public boolean isSatisfied() {
181 return ChildProcessLauncher.connectedServicesCountForTes ting() == 1;
182 }
183 }));
184
185 assertTrue("The connection failed to get a pid in setup.",
186 CriteriaHelper.pollForCriteria(new Criteria() {
187 @Override
188 public boolean isSatisfied() {
189 return connection.getPid() != 0;
190 }
191 }));
192
193 // Crash the service.
194 assertTrue(connection.crashServiceForTesting());
195
196 // Verify that a new service is started for the pending spawn.
197 assertTrue("Failed to spawn from queue.",
198 CriteriaHelper.pollForCriteria(new Criteria() {
199 @Override
200 public boolean isSatisfied() {
201 return ChildProcessLauncher.pendingSpawnsCountForTesting () == 0;
202 }
203 }));
204
205 assertTrue("The connection wasn't allocated for the pending spawn.",
206 CriteriaHelper.pollForCriteria(new Criteria() {
207 @Override
208 public boolean isSatisfied() {
209 return ChildProcessLauncher.allocatedConnectionsCountFor Testing(
210 appContext) == 1;
211 }
212 }));
213
214 // Verify that the connection completes the setup for the pending spawn.
215 assertTrue("The connection wasn't registered in ChildProcessLauncher aft er setup.",
216 CriteriaHelper.pollForCriteria(new Criteria() {
217 @Override
218 public boolean isSatisfied() {
219 return ChildProcessLauncher.connectedServicesCountForTes ting() == 1;
220 }
221 }));
222 }
223
141 private ChildProcessConnectionImpl startConnection() throws InterruptedExcep tion { 224 private ChildProcessConnectionImpl startConnection() throws InterruptedExcep tion {
142 // Allocate a new connection. 225 // Allocate a new connection.
143 Context context = getInstrumentation().getTargetContext(); 226 Context context = getInstrumentation().getTargetContext();
144 final ChildProcessConnectionImpl connection = (ChildProcessConnectionImp l) 227 final ChildProcessConnectionImpl connection = (ChildProcessConnectionImp l)
145 ChildProcessLauncher.allocateBoundConnectionForTesting(context); 228 ChildProcessLauncher.allocateBoundConnectionForTesting(context);
146 229
147 // Wait for the service to connect. 230 // Wait for the service to connect.
148 assertTrue("The connection wasn't established.", 231 assertTrue("The connection wasn't established.",
149 CriteriaHelper.pollForCriteria(new Criteria() { 232 CriteriaHelper.pollForCriteria(new Criteria() {
150 @Override 233 @Override
151 public boolean isSatisfied() { 234 public boolean isSatisfied() {
152 return connection.isConnected(); 235 return connection.isConnected();
153 } 236 }
154 })); 237 }));
155 return connection; 238 return connection;
156 } 239 }
157 240
158 @Override 241 @Override
159 protected void setUp() throws Exception { 242 protected void setUp() throws Exception {
160 super.setUp(); 243 super.setUp();
161 LibraryLoader.ensureInitialized(); 244 LibraryLoader.ensureInitialized();
162 } 245 }
163 } 246 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698