uiautomator
uiautomator copied to clipboard
Properly acquire local port after calculating it.
This makes the AutomatorServer to properly acquire the local port chosen for forwarding traffic to the server running on the device, so that other instances of uiautomator-based scripts don't acquire it before the current instance.
Before the port was selected on AutomatorService instantiation (which is happening on AutomatorDevice instantiation), but only allocated on the first real query, which could cause issues when running two processes on the same machine. I.e. the following sequence of events would lead to two tests talking to the same device:
Process 1: device = uiautomator.Device(serial="1") // selected local port 9008 Process 2: device = uiautomator.Device(serial="2") // selected local port 9008 (because it's still free) Process 1: device.screen.on() // forwarded local port 9008 Process 2: device.screen.on() // re-forwarded local port 9008, because it doesn't now that it's already forwarded // now both processes talk to device with serial="2"
Now we do not select port on instantiation, but select and forward it when we actually need it first time. After trying to forward it it also checks whether the forwarding was successful, because some other process could do the forwarding in the meantime.
Also this changed port forwarding to use "no-rebind" parameter, which doesn't allow port to be silently re-forwarded, so if some other process forwards it before us we don't mess it.
@mcdaniel67 Addressed your comments, thanks!
What's the status on this repo?