Skip to content

Commit ed261c4

Browse files
committed
fix(ios): report the Mac once when device lookups overlap
1 parent fc5f3c0 commit ed261c4

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎lib/common/mobile/mobile-core/ios-mac-device-discovery.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class IOSMacDeviceDiscovery extends DeviceDiscovery {
4949
}
5050

5151
const hardware = await this.getHardware();
52-
if (!hardware) {
52+
// An overlapping lookup may have added the Mac during the await.
53+
if (!hardware || this.isDeviceAdded) {
5354
return;
5455
}
5556

‎lib/common/test/unit-tests/mobile/ios-mac-device-discovery.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,26 @@ describe("iOSMacDeviceDiscovery", () => {
140140
assert.lengthOf(found, 1);
141141
});
142142

143+
it("reports the Mac once when lookups overlap", async () => {
144+
const discovery = createTestInjector({}).resolve<IOSMacDeviceDiscovery>(
145+
"iOSMacDeviceDiscovery",
146+
);
147+
const found: Mobile.IDevice[] = [];
148+
discovery.on(DeviceDiscoveryEventNames.DEVICE_FOUND, (d: Mobile.IDevice) =>
149+
found.push(d),
150+
);
151+
const options = <Mobile.IDeviceLookingOptions>{
152+
platform: "ios",
153+
deviceId: "mac",
154+
};
155+
156+
await Promise.all([
157+
discovery.startLookingForDevices(options),
158+
discovery.startLookingForDevices(options),
159+
]);
160+
assert.lengthOf(found, 1);
161+
});
162+
143163
it("leaves the Mac out of a run that doesn't name it", async () => {
144164
const found = await discover(createTestInjector({}), { platform: "ios" });
145165
assert.lengthOf(found, 0);

0 commit comments

Comments
 (0)