Properly acquire local port after calculating it.#208
Open
artikz wants to merge 4 commits intoxiaocong:masterfrom
Open
Properly acquire local port after calculating it.#208artikz wants to merge 4 commits intoxiaocong:masterfrom
artikz wants to merge 4 commits intoxiaocong:masterfrom
Conversation
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.
mcdaniel67
reviewed
May 18, 2017
test/test_server.py
Outdated
|
|
||
| def test_start_success(self): | ||
| server = AutomatorServer() | ||
| server = AutomatorServer(local_port=1234) |
There was a problem hiding this comment.
Thoughts on using a helper to create the AutomatorServer so each test doesn't have to specify local_port?
uiautomator/__init__.py
Outdated
| self.adb.cmd("install", "-r -t", os.path.join(base_dir, apk)).wait() | ||
|
|
||
| def get_forwarded_port(self): | ||
| for s, lp, rp in self.adb.forward_list(): |
There was a problem hiding this comment.
s, lp, rp could be named better. Also, I know this module doesn't have the best documentation, but I think a docstring would be good.
| return None | ||
|
|
||
| @property | ||
| def local_port(self): |
| return dict([s.split("\t") for s in out[index + len(match):].strip().splitlines() if s.strip()]) | ||
|
|
||
| def forward(self, local_port, device_port): | ||
| def forward(self, local_port, device_port, rebind=True): |
There was a problem hiding this comment.
Would be good to add some test coverage here.
Author
|
@mcdaniel67 Addressed your comments, thanks! |
mcdaniel67
approved these changes
May 22, 2017
There was a problem hiding this comment.
Looks good to me, other than needing a pre-merge commit squash. I rebased this on top of my fix for travis and pushed it up to my fork to get a travis run.
https://travis-ci.org/mcdaniel67/uiautomator/builds/234656251
|
What's the status on this repo? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.