Skip to content

Commit 1e62e04

Browse files
author
PR Batch Tester
committed
fix(devices): keep Android AVD opens concurrent
1 parent 30811fe commit 1e62e04

2 files changed

Lines changed: 30 additions & 17 deletions

File tree

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,31 @@ describe("device setup consent", () => {
310310
}).pipe(Effect.scoped),
311311
);
312312

313-
it.effect("boots a stopped Android AVD and uses its emulator serial without duplicating it", () =>
314-
Effect.gen(function* () {
315-
const { service, requests } = yield* fixture();
316-
yield* service.configure({ enabled: true });
317-
const session = yield* service.open({
318-
threadId: ThreadId.make("thread-1"),
319-
deviceId: "Pixel_API_35",
320-
platform: "android",
321-
});
322-
expect(session.deviceId).toBe("emulator-5554");
323-
expect(requests.filter((url) => url.endsWith("/boot"))).toHaveLength(1);
324-
const state = yield* service.state;
325-
expect(state.devices.map((device) => device.id)).toEqual(["emulator-5554"]);
326-
expect(state.bootingDevices).toEqual([]);
327-
}).pipe(Effect.scoped),
313+
it.effect.each([1, 2])(
314+
"opens a stopped Android AVD from %s threads using its emulator serial",
315+
(count) =>
316+
Effect.gen(function* () {
317+
const { service, requests } = yield* fixture();
318+
yield* service.configure({ enabled: true });
319+
const sessions = yield* Effect.all(
320+
Array.from({ length: count }, (_, index) =>
321+
service.open({
322+
threadId: ThreadId.make(`thread-${index}`),
323+
deviceId: "Pixel_API_35",
324+
platform: "android",
325+
}),
326+
),
327+
{ concurrency: "unbounded" },
328+
);
329+
expect(sessions.map((session) => session.deviceId)).toEqual(
330+
Array(count).fill("emulator-5554"),
331+
);
332+
expect(requests.filter((url) => url.endsWith("/boot"))).toHaveLength(count);
333+
const state = yield* service.state;
334+
expect(state.sessions).toHaveLength(count);
335+
expect(state.devices.map((device) => device.id)).toEqual(["emulator-5554"]);
336+
expect(state.bootingDevices).toEqual([]);
337+
}).pipe(Effect.scoped),
328338
);
329339

330340
it.effect("blocks only emulator video until ffmpeg is usable, then allows retry", () =>

‎apps/server/src/device/DeviceService.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
714714
}
715715
});
716716

717-
// The hub fails stream setup that overlaps another on the same device, so its opens take turns.
717+
// serve-sim rejects overlapping iOS stream setup on the same device.
718718
const openLocks = new Map<string, Semaphore.Semaphore>();
719719
const withOpenLock = (hostId: DeviceHostId, deviceId: DeviceId) => {
720720
const key = `${hostId}\u0000${deviceId}`;
@@ -833,7 +833,10 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
833833
);
834834
return session;
835835
},
836-
(effect, input) => withOpenLock(input.hostId ?? LOCAL_DEVICE_HOST_ID, input.deviceId)(effect),
836+
(effect, input) =>
837+
input.platform === "ios"
838+
? withOpenLock(input.hostId ?? LOCAL_DEVICE_HOST_ID, input.deviceId)(effect)
839+
: effect,
837840
);
838841

839842
const shutdownDevice = Effect.fn("DeviceService.shutdownDevice")(function* (

0 commit comments

Comments
 (0)