#2042: remove apply_timestep() return value
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user