Skip to content

Commit

Permalink
Fix an issue with overriding the network delay, and test it.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira Emma Hopwood <[email protected]>
  • Loading branch information
daira committed Oct 20, 2023
1 parent 3d4a647 commit 224faee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions simtfl/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def initialize(self, ident, env, network):
def __str__(self):
return f"{self.__class__.__name__}"

def send(self, target, message):
def send(self, target, message, delay=None):
"""
(process) This method can be overridden to intercept messages being sent
by this node. The implementation in this class calls `self.network.send`.
"""
return self.network.send(self.ident, target, message)
return self.network.send(self.ident, target, message, delay=delay)

def receive(self, sender, message):
"""
Expand Down Expand Up @@ -158,6 +158,9 @@ def run(self):
yield from self.send(0, PayloadMessage(i))
yield self.env.timeout(1)

# Test overriding the propagation delay. This message
# is sent at time 3 and received at time 11.
yield from self.send(0, PayloadMessage(3), delay=8)

class TestFramework(unittest.TestCase):
def _test_node(self, receiver_node, expected):
Expand All @@ -176,6 +179,7 @@ def test_passive_node(self):
(1, PayloadMessage(0), 1),
(1, PayloadMessage(1), 2),
(1, PayloadMessage(2), 3),
(1, PayloadMessage(3), 11),
])

def test_sequential_node(self):
Expand All @@ -187,4 +191,5 @@ def test_sequential_node(self):
(1, PayloadMessage(0), 1),
(1, PayloadMessage(1), 4),
(1, PayloadMessage(2), 7),
(1, PayloadMessage(3), 11),
])

0 comments on commit 224faee

Please sign in to comment.