Skip to content

Commit

Permalink
Fix cirque - update int/pointer casting and reset subscription counts…
Browse files Browse the repository at this point in the history
… in tests. (project-chip#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.
  • Loading branch information
cecille authored Oct 21, 2021
1 parent f45f50b commit b5ad57f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit b5ad57f

Please sign in to comment.