From 39c743312a1b688f4a105c58b0ce6b4dc0e45c48 Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Wed, 20 Oct 2021 09:43:47 -0400 Subject: [PATCH 1/2] Fix GetConnectedDeviceSync The returned device pointer is actually an int type, which meant that the function never actually waited for a callback and was racing on the device resolve when it attempted to send commands. Test: Saw regular cirque failures after device resolve. After this change, saw a resolve wait for the callback as expected. --- src/controller/python/chip/ChipDeviceCtrl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 4cc6afc1744eca..c7bdab23248378 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -317,7 +317,7 @@ def DeviceAvailableCallback(device, err): nonlocal returnDevice nonlocal deviceAvailableCV with deviceAvailableCV: - returnDevice = device + returnDevice = c_void_p(device) deviceAvailableCV.notify_all() if err != 0: print("Failed in getting the connected device: {}".format(err)) @@ -330,11 +330,11 @@ def DeviceAvailableCallback(device, err): # The callback might have been received synchronously (during self._ChipStack.Call()). # Check if the device is already set before waiting for the callback. - if returnDevice == c_void_p(None): + if returnDevice.value == None: with deviceAvailableCV: deviceAvailableCV.wait() - if returnDevice == c_void_p(None): + if returnDevice.value == None: raise self._ChipStack.ErrorToException(CHIP_ERROR_INTERNAL) return returnDevice From 0e3179244a8963b60f8d0ad63e0fe0eaaffe5f8a Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Wed, 20 Oct 2021 21:33:46 -0400 Subject: [PATCH 2/2] Fix Subscription test. The subscription itself causes a callback, which throws off the count between the number of commands and the check. The result is that the check ends, but the change thread continues on and causes weird races with the remaining tests. Resets the count right before the check and adds a thread join. --- src/controller/python/test/test_scripts/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controller/python/test/test_scripts/base.py b/src/controller/python/test/test_scripts/base.py index 460bab180bb694..677264f5f38ba7 100644 --- a/src/controller/python/test/test_scripts/base.py +++ b/src/controller/python/test/test_scripts/base.py @@ -344,11 +344,14 @@ def run(self): "OnOff", "OnOff", nodeid, endpoint, 1, 10) changeThread = _conductAttributeChange( self.devCtrl, nodeid, endpoint) + # Reset the number of subscriptions received as subscribing causes a callback. + handler.subscriptionReceived = 0 changeThread.start() with handler.cv: while handler.subscriptionReceived < 5: # We should observe 10 attribute changes handler.cv.wait() + changeThread.join() return True except Exception as ex: self.logger.exception(f"Failed to finish API test: {ex}")