From 3f76e095214a4fbf44e96cb5c05913250cb2c25a Mon Sep 17 00:00:00 2001 From: Nick Todd Date: Wed, 22 Nov 2023 14:13:50 +0000 Subject: [PATCH] #2042: remove apply_timestep() return value --- .../simulator/system/services/ntp/ntp_client.py | 9 +++------ .../system/test_ntp_client_server.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index 81ec031c..51df5010 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -66,6 +66,7 @@ class NTPClient(Service): :return: True if successful, False otherwise. """ + self.ip_addr = payload.ntp_request.ntp_client self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}") return super().send( @@ -92,10 +93,7 @@ class NTPClient(Service): _LOGGER.debug(f"{payload} is not a NTPPacket") return False if payload.ntp_reply.ntp_datetime: - self.sys_log.info( - f"{self.name}: Received time \ - update from NTP server{payload.ntp_reply.ntp_datetime}" - ) + self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") self.time = payload.ntp_reply.ntp_datetime return True @@ -110,13 +108,12 @@ class NTPClient(Service): :param timestep: The current timestep number. (Amount of time since simulation episode began) :type timestep: int """ + self.sys_log.info(f"{self.name} apply_timestep: IP address: {self.ip_addr}") super().apply_timestep(timestep) if self.operating_state == ServiceOperatingState.RUNNING: # request time from server ntp_request = NTPRequest(ntp_client=self.ip_addr) ntp_server_packet = NTPPacket(ntp_request=ntp_request) self.send(payload=ntp_server_packet) - return True else: self.sys_log.debug(f"{self.name} ntp client not running") - return False diff --git a/tests/integration_tests/system/test_ntp_client_server.py b/tests/integration_tests/system/test_ntp_client_server.py index 48db0cbb..95394e84 100644 --- a/tests/integration_tests/system/test_ntp_client_server.py +++ b/tests/integration_tests/system/test_ntp_client_server.py @@ -1,4 +1,5 @@ from ipaddress import IPv4Address +from time import sleep import pytest @@ -61,11 +62,17 @@ def test_ntp_client_server(): assert ntp_server.receive(payload=ntp_packet) is True assert ntp_client.receive(payload=ntp_packet) is True assert ntp_client.time is not None - assert ntp_client.apply_timestep(1) is True + first_time = ntp_client.time + sleep(0.1) + ntp_client.apply_timestep(1) # Check time advances + ntp_server.receive(payload=ntp_packet) + ntp_client.receive(payload=ntp_packet) + second_time = ntp_client.time + assert first_time != second_time # Test ntp client behaviour when ntp server is unavailable. -@pytest.mark.skip(reason="NTP needs to know if underly node is RUNNING") +@pytest.mark.skip(reason="NTP needs to know if underlying node is RUNNING") def test_ntp_server_failure(): network = create_ntp_network() server: Server = network.get_node_by_hostname("ntp_server")