#2042: ntp_client test
This commit is contained in:
@@ -100,7 +100,7 @@ class NTPClient(Service):
|
|||||||
|
|
||||||
def apply_timestep(self, timestep: int) -> None:
|
def apply_timestep(self, timestep: int) -> None:
|
||||||
"""
|
"""
|
||||||
For each timestep request the time tfrom the NTP server.
|
For each timestep request the time from the NTP server.
|
||||||
|
|
||||||
In this instance, if any multi-timestep processes are currently
|
In this instance, if any multi-timestep processes are currently
|
||||||
occurring (such as restarting or installation), then they are brought one step closer to
|
occurring (such as restarting or installation), then they are brought one step closer to
|
||||||
@@ -114,3 +114,7 @@ class NTPClient(Service):
|
|||||||
# request time from server
|
# request time from server
|
||||||
ntp_request = NTPPacket(NTPRequest())
|
ntp_request = NTPPacket(NTPRequest())
|
||||||
self.send(ntp_request)
|
self.send(ntp_request)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.sys_log.debug(f"{self.name} ntp client not running")
|
||||||
|
return False
|
||||||
|
|||||||
25
tests/integration_tests/system/test_ntp_client_server.py
Normal file
25
tests/integration_tests/system/test_ntp_client_server.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from primaite.simulator.network.hardware.nodes.computer import Computer
|
||||||
|
from primaite.simulator.network.hardware.nodes.server import Server
|
||||||
|
from primaite.simulator.network.protocols.ntp import NTPPacket
|
||||||
|
from primaite.simulator.system.services.ntp.ntp_client import NTPClient
|
||||||
|
from primaite.simulator.system.services.ntp.ntp_server import NTPServer
|
||||||
|
from primaite.simulator.system.services.service import ServiceOperatingState
|
||||||
|
|
||||||
|
# Define one node to be an NTP server and another node to be a NTP Client.
|
||||||
|
|
||||||
|
|
||||||
|
def test_ntp_client_server(network):
|
||||||
|
server: Server = network.get_node_by_hostname("ntp_server")
|
||||||
|
client: Computer = network.get_node_by_hostname("ntp_client")
|
||||||
|
|
||||||
|
ntp_server: NTPServer = server.software_manager.software["NTP_Server"]
|
||||||
|
ntp_client: NTPClient = client.software_manager.software["NTP_Client"]
|
||||||
|
|
||||||
|
assert ntp_server.operating_state == ServiceOperatingState.RUNNING
|
||||||
|
assert ntp_client.operating_state == ServiceOperatingState.RUNNING
|
||||||
|
|
||||||
|
ntp_client.send(payload=NTPPacket())
|
||||||
|
assert ntp_server.receive() is True
|
||||||
|
assert ntp_client.receive() is True
|
||||||
|
|
||||||
|
assert ntp_client.apply_timestep(1) is True
|
||||||
Reference in New Issue
Block a user