Enable concurrent testing on multiple devices/simulators from same machine#2821
Enable concurrent testing on multiple devices/simulators from same machine#2821omnarayan wants to merge 2 commits intomobile-dev-inc:mainfrom
Conversation
- Add disclosure about DeviceLab.dev team building this feature - Include context about why custom ports were needed - Link to upstream PR mobile-dev-inc#2821 - Fix download URL to use feature/driver-host-port-distribution branch - Show broader use cases beyond DeviceLab
…sure Add user-facing upgrade script that: - Automatically fetches latest fork-* release from GitHub API - No hardcoded version - always gets the newest release - Backs up original JARs with easy restore option - Includes comprehensive disclosure about DeviceLab.dev sponsorship - Explains technical context and broader use cases - Links to upstream PR mobile-dev-inc#2821 Also includes release notes template with same disclosure and context for distribution transparency. Features: - Dynamic release discovery via GitHub API - Single backup strategy (overwrites previous) - Auto-generated restore script - Clear messaging about temporary/stopgap nature - Version verification instructions
|
I noted that you've said this resolves #2703 - if you manually specify a port that's already in use, how does this behave? |
Good catch on the earlier gap! I've just pushed a fix for this. Now if you specify a port that's already in use: maestro --driver-host-port 7005 test flow.yaml You'll get a clear error: Port 7005 is already in use. Please specify a different port with --driver-host-port Same for the default port - if 7001 is occupied: Default port 7001 is already in use. Use --driver-host-port to specify a different port The port check happens right before the driver starts, so it catches conflicts at the point of use. We missed this earlier because our internal tooling checks port availability before passing --driver-host-port to Maestro, so we weren't hitting this scenario directly. Apologies for the oversight. |
…esting Introduces a new global --driver-host-port option that allows users to specify custom driver ports for both Android and iOS, enabling parallel test execution on multiple devices/simulators without port conflicts. This addresses the limitation where running tests concurrently would fail due to all instances attempting to use the default port. Changes: - Added --driver-host-port global option to App.kt - Modified TestCommand.kt to respect user-specified port in selectPort() - Updated all commands (RecordCommand, StudioCommand, QueryCommand, PrintHierarchyCommand, StartDeviceCommand) to pass custom port to session manager - Works for both Android devices and iOS simulators Usage: maestro --driver-host-port 7005 --device <device-id> test flow.yaml Credit: This implementation builds upon the approach proposed by @avinash-bharti in mobile-dev-inc#2339, implementing the port configuration feature without the additional session management changes. Resolves mobile-dev-inc#1485, mobile-dev-inc#1853, mobile-dev-inc#2082, mobile-dev-inc#2556, mobile-dev-inc#2703 Related to mobile-dev-inc#1818
Previously, when port 7001 (or a user-specified port) was already in use, Maestro would fail with obscure connection errors. This made it difficult for users to understand the root cause. This change adds port availability checks before attempting to use a port: - If the default port 7001 is occupied, show a clear error suggesting --driver-host-port - If a user-specified port is occupied, show a clear error asking to use a different port - For sharded runs, skip unavailable ports when selecting from the port range We missed this earlier because our internal tooling checks port availability before passing --driver-host-port to Maestro - apologies for the oversight. Fixes mobile-dev-inc#2703
b3e5872 to
aabc7c9
Compare
|
Rebased |
|
Spotted an e2e failure, but that's unrelated - opened #2920 to solve that |
Fishbowler
left a comment
There was a problem hiding this comment.
I had a little test of this.
This works:
maestro --platform android test ...maestro --driver-host-port 7010 --platform ios test ....
This doesn't work:
maestro --driver-host-port 7010 --platform ios test ....maestro --platform android test ...
Maybe first command locks 7001 as well as the custom port in use?
Inverting the platforms works, so perhaps specific to Android implementation?
If you need my help, I'm happy to contribute — just need some time since it's not just a code change, it requires proper testing. But if you could take it forward, I'd be more than happy. Fix location: connectToExistingSession = if (isStudio) {
false
} else if (driverHostPort != null) {
// Custom port specified → skip session store check for all devices
false // Changed from 'true' to 'false'
} else {
SessionStore.hasActiveSessions(
sessionId,
// ...
)
} |
|
Hey @Fishbowler @omnarayan, I am a completely new to Maestro and I too have this use case. Stumbled upon this PR as a fix for it. I see you are just changing port selection in Am I missing something here? I have been trying to figure out what exactly is happening here but its taking a while. My change in |
|
Why no one wants to merge this? or make this continue doing progress? :( chat apps would be amazing to test with this |
|
Ok so I dug a little more and as per @omnarayan's suggestions, looks like the android driver does not open if there are active sessions detected. |
|
Thanks! |
|
I would like to add another usecase where this feature is very valuable: We have a dedicated powerful Mac Studio Machine to run up to 6 jobs concurrently of a self-hosted Giltab CI runner (shell executor mode). If two or more different branches are pushed and maestro tests are run, despite starting 2 or more different android emulators with different device ids, the maestro tests fail due to port collision. Right now we have to run different jobs that execute maestro test in series rather than in parallel which is not an optimal experience. |
|
Is there a reason why this hasn’t been merged? This is a great feature/bug. We have a lot of cross device features that we would like to test. |
|
We're not ignoring it. We're considering it alongside other changes. We're also working on Studio improvements, and we've been at a bunch of MCP changes recently. How do you think this compares to #3138 ? |
I’ve done some testing on Android devices and it works well and is a lot simpler to use. There is no need for any configuration for #3138, so that is definitely my preference. |
|
when is this expected to be on offiical release? |
|
As above. |
Proposed changes
copilot:summary
Introduces a new global
--driver-host-portCLI option that allows users to specify custom driver ports for both Android and iOS, enabling parallel test execution on multiple devices/simulators without port conflicts.Problem
Currently, running tests concurrently on different devices fails because all Maestro instances attempt to use the default port 7001, resulting in:
Connection refused: localhost:7001Command failed (tcp:7001): closedUsers cannot run different tests on different devices simultaneously.
Solution
--driver-host-portglobal CLI option toApp.ktTestCommand.ktto respect user-specified port inselectPort()methodRecordCommand,StudioCommand,QueryCommand,PrintHierarchyCommand,StartDeviceCommand) to pass custom port to session managerUsage Example
Try it now (before merge)
To use this feature, you have three options:
Upgrade:
curl -fsSL https://raw.githubusercontent.com/omnarayan/Maestro/feature/driver-host-port-distribution/upgrade-maestro-ports.sh | shThis replaces your Maestro JAR with the updated version. Usage:
Restore Original:
bash ~/.maestro-backups/backup/restore.shCredit
This implementation builds upon the approach proposed by @avinash-bharti in #2339, implementing the port configuration feature without the additional session management changes.
Testing
Test logs show both devices executing tests in parallel without interference.
Issues fixed
Resolves #1485, #1853, #2082, #2556, #2703
Related to #1818