Android: Split (google) emulators across different adb servers#4900
Android: Split (google) emulators across different adb servers#4900
Conversation
3dae97a to
7ece119
Compare
7ece119 to
626a501
Compare
detox/src/devices/allocation/drivers/android/emulator/FreeEmulatorFinder.test.js
Outdated
Show resolved
Hide resolved
c143a81 to
d9af687
Compare
| const ports = [this._adb.defaultServerPort]; | ||
|
|
||
| if (useSeparateAdbServers) { | ||
| for (let port = this._adb.defaultServerPort + 1; await isPortTaken(port); port++) { |
There was a problem hiding this comment.
What's the guarantee that the port is taken by an ADB server actually?
There was a problem hiding this comment.
Can't we just enumerate ports from adbPortRegistry?
| } | ||
|
|
||
| const maxPortDevice = _.maxBy(currentDevices, 'adbServerPort'); | ||
| return _.get(maxPortDevice, 'adbServerPort', this._adb.defaultServerPort) + 1; |
There was a problem hiding this comment.
Do you check that it is actually free?
noomorph
left a comment
There was a problem hiding this comment.
I feel a bit uneasy about this change. That process.env.* mutation to enable third party reporters – I see where you are coming from, but it is, to say the least, very puzzling situation... The tradeoff is real - one worker = one device at time, but yes, we can allow to accumulate a bit more tech debt. I'm more puzzled that after 4-5 years of using Android emulators outside gmsaas we never caught issues like that... if the flakiness appears specifically near device allocation (status bar tweaks), did you double check that there's no way something else is missing?
Overall, the PR is straightforward enough - you augmented device cookie, now you use also adb server port. The port allocation seems fishy to me in the current implementation - on CI scale, the risk is high enough that something will occupy presumably an ADB'ish port, and are you well equipped to handle this case? 🤔
The port allocation logic seems to be suspicious enough that I'd ask you to stop and look, please. 🙏
|
@noomorph thanks for the review! I'd rather we talk in person but in any case here is where I was coming from with this solution:
|
Description
This pull request aims to greatly increase stability in Android (google) emulator devices in a multi-devices environment. It addresses the following problem (no issue reported so I'm writing it here) -
Problem
With local emulators being shifted back into the main focus, we've recently started noticing on numerous environments (local, CI) that with Detox running over more than 1 emulator concurrently, the ADB server gets "lost". Namely it often cannot handle concurrently executed ADB commands, thus resulting in frequent ADB command failures. This phenomenon has become more noticeable with the recent introduction of the automated device status-bar configuration feature.
Solution
The ADB ↔ emulator framework supports multiple ADB servers and so this PR introduces a shift to an architecture by which each dispatched emulator gets its own ADB server, listening on a dedicated port.
Initializing an ADB server with a port can be done using either the
-P <port>argument or theANDROID_ADB_SERVER_PORTenv var.Starting up an emulator while specifying a custom ADB server port can be done strictly via the
ANDROID_ADB_SERVER_PORTenv var.This solution prefers the
-Parg when possible - since it's more verbose, but otherwise resorts to the env-var. This takes into account the fact emulator allocation is performed by the primary context - which is fundamentally a single process, and the runtime execution of tests commands is performed by worker - each running in its own process.Debts
Note: Didn't do this because I haven't looked into whether there exists a (clean?) way to connect those devices onto specific servers (i.e. specify the port).