Skip to content

Commit

Permalink
Improve notifications handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alabou authored and jonathan-r-thorpe committed Nov 11, 2024
1 parent f1261d1 commit 05f24f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 18 additions & 4 deletions nmostesting/IS12Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .GenericTest import NMOSInitException, NMOSTestException
from .TestHelper import WebsocketWorker, load_resolved_schema
from .MS05Utils import NcBlockMethods, NcClassManagerMethods, NcEventId, NcMethodStatus, NcObjectMethods, \
NcPropertyChangedEventData
NcPropertyChangedEventData, NcObjectProperties

CONTROL_API_KEY = "ncp"
MS05_API_KEY = "controlframework"
Expand Down Expand Up @@ -76,6 +76,8 @@ def reset(self):
super().reset()
self.command_handle = 0
self.expect_notifications = False
self.expect_notifications_oid = 0
self.expect_notifications_property = None
self.notifications = []

# Overridden functions
Expand Down Expand Up @@ -159,7 +161,7 @@ def send_command(self, test, command_json):

results = []
start_time = time.time()
while time.time() < start_time + WS_MESSAGE_TIMEOUT:
while time.time() < start_time + 2* WS_MESSAGE_TIMEOUT: # have enough time for command and notifications
if not self.ncp_websocket.is_messages_received():
time.sleep(0.2)
continue
Expand Down Expand Up @@ -198,7 +200,14 @@ def send_command(self, test, command_json):
if not self.expect_notifications and len(results) != 0:
break
if self.expect_notifications and len(results) != 0 and len(self.notifications) != 0:
break
found_oid = False
for notification in self.notifications:
if notification.oid == self.expect_notifications_oid and notification.eventData.propertyId == self.expect_notifications_property:
found_oid = True
break

if found_oid:
break

if len(results) == 0:
raise NMOSTestException(test.FAIL(
Expand All @@ -209,13 +218,18 @@ def send_command(self, test, command_json):
if len(results) > 1:
raise NMOSTestException(test.FAIL(f"Received multiple responses : {len(responses)}"))

if self.expect_notifications and len(self.notifications) == 0:
raise NMOSTestException(test.FAIL("expected notifications not received in time"))

return results[0]

def get_notifications(self):
return self.notifications

def start_logging_notifications(self):
def start_logging_notifications(self, oid, property):
self.expect_notifications = True
self.expect_notifications_oid = oid
self.expect_notifications_property = property
self.notifications = []

def stop_logging_notifications(self):
Expand Down
7 changes: 4 additions & 3 deletions nmostesting/suites/IS1201Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ def test_33(self, test):
# Each label will be set twice; once to the new user label, and then again back to the old user label
for label in [new_user_label, old_user_label]:
# Set property and log notificaiton
self.is12_utils.start_logging_notifications()
self.is12_utils.start_logging_notifications(oid, NcObjectProperties.USER_LABEL.value)
method_result = self.is12_utils.set_property(test, NcObjectProperties.USER_LABEL.value, label, oid=oid)
self.is12_utils.stop_logging_notifications()

if isinstance(method_result, NcMethodResultError):
error = True
error_message += f"Unable to set user label property from object (OID:{str(oid)}): " \
f"{str(method_result.errorMessage)} "
continue
self.is12_utils.stop_logging_notifications()

for notification in self.is12_utils.get_notifications():
if notification.oid == oid:
Expand All @@ -314,7 +315,7 @@ def test_33(self, test):
if notification.eventData.propertyId != NcObjectProperties.USER_LABEL.value:
continue

if notification.eventData.changeType != NcPropertyChangeType.ValueChanged:
if notification.eventData.changeType != NcPropertyChangeType.ValueChanged.value:
error = True
error_message += f"{context}Unexpected change type: " \
f"{str(notification.eventData.changeType.name)}, "
Expand Down

0 comments on commit 05f24f2

Please sign in to comment.