From b5ad57fada3f391d4610fe89b9d38765744339c0 Mon Sep 17 00:00:00 2001 From: C Freeman Date: Thu, 21 Oct 2021 11:09:01 -0400 Subject: [PATCH] Fix cirque - update int/pointer casting and reset subscription counts in tests. (#10771) * 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. * 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/chip/ChipDeviceCtrl.py | 6 +++--- src/controller/python/test/test_scripts/base.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 03a5cccf524b33..f7f2f328b93559 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -318,7 +318,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)) @@ -331,11 +331,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 diff --git a/src/controller/python/test/test_scripts/base.py b/src/controller/python/test/test_scripts/base.py index 5aab196a1ac088..031d2280500fa8 100644 --- a/src/controller/python/test/test_scripts/base.py +++ b/src/controller/python/test/test_scripts/base.py @@ -343,11 +343,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}")