Closed sebkur closed 1 year ago
Use handle_usb_disconnect
as a context, and perform the disconnect/reconnect within the context.
Thanks! I'm not sure I've understood this correctly, but this is what I figured out now and which seems to be working:
def test_basic_discovery(self):
self.droid1.pm.startActivity()
self.droid2.pm.startActivity()
self.droid1.pm.startAdvertising()
self.droid2.pm.startDiscovery()
with self.droid1.handle_usb_disconnect():
with self.droid2.handle_usb_disconnect():
maxWaitDisconnect = 10
print("waiting for disconnect for", maxWaitDisconnect, "seconds")
time.sleep(maxWaitDisconnect)
print("wait for device 1")
self.droid1.adb.wait_for_device()
print("wait for device 2")
self.droid2.adb.wait_for_device()
I'm giving the test user 10 seconds time to disconnect one or more of the devices running the tests and the tests will continue running on-device until the user reconnects all previously disconnected devices. This fits our scenario of what we're trying to do, i.e. let some app run for a while on the devices until they're all plugged back into the host where logs are collected.
I'm not sure how this would scale to a variable number of devices, i.e. if one wanted to write this code so that it would not operate on exactly two devices but for example on a list of devices. Putting the with self.droid1.handle_usb_disconnect():
into a loop probably won't work... It's not crucial for me, just curious if this is generally possible and also if the way I'm doing it now seems reasonable.
I think it would probably be great to add an example to the Mobly repository that does something like this. It doesn't seem straightforward to figure this out and there also doesn't seem to be any real-world code that uses handle_usb_disconnect()
. Try a Github code search: https://github.com/search?q=handle_usb_disconnect&type=code it only turns up occurrences in mobly itself where the method is defined or in forks.
Thanks for this library, it seems very useful!
I've got a lot of basic things working after going through the tutorials, but now I'm stuck with making my tests continue working even when disconnecting one of the devices.
Here's my code:
It loads a snippet on two devices, starts some activity and make it do something. Then I wait for 30 seconds in which I disconnect one of the devices from USB and reconnect it. Afterwards, Mobly succeeds to finish the activity on the device that was connected all along but fails to do so on the one that had been temporarily disconnected.
I get some errors on stdout:
I also tried to wait for the devices at the end of the test, but that didn't help, like this:
I also tried various things with
handle_usb_disconnect()
but also couldn't make it fix anything.Do you have any idea how to solve this? I have the feeling Mobly is designed to handle this kind of situation and I'm missing something obvious. I think an example on this would be beneficial for the community as disconnecting devices during a test and reconnecting it for logs collection seems to me like something that could be a very common situation. Thanks!