-
Notifications
You must be signed in to change notification settings - Fork 205
Closed
Description
The _stop_port_forwarding() method in mobly.controllers.android_device_lib.snippet_client_v2.SnippetClientV2 currently attempts to remove adb port forwarding without verifying whether the port is still in use.
This can lead to noisy errors or misleading logs when the port is already released (or was never forwarded).
Proposal
Modify _stop_port_forwarding() to:
- Check
adb.list_occupied_adb_ports()before attempting removal. - Skip the
--removecall if the port is not found. - Ensure proper debug logging and safe cleanup via
finally.
Additional Improvements
- Minor readability enhancements (docstrings, logging).
- Related unit tests updated to match logic changes.
- All tests pass via
tox, and code is linted viapyink==24.3.0.
Rationale
This change improves robustness, avoids unnecessary adb commands, and aligns with the defensive coding pattern Mobly uses elsewhere (e.g., list_occupied_adb_ports()'s intended usage).
I’d like to contribute this improvement. Please let me know if you'd like it broken into smaller parts or if there's existing related work I should refer to.