Skip to content

Commit

Permalink
Improve unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbruno25 committed Dec 27, 2023
1 parent 8e3792b commit 9469332
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/back2back_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,22 @@ def test_sub_second_timestamp_resolution(self):
self.bus2.recv(0)
self.bus2.recv(0)

def test_perodic_tasks_do_not_exceed_duration(self):
duration, period = 2.0, 0.6
messages = []

self.bus2.send_periodic(can.Message(), period, duration)
while True:
msg = self.bus1.recv(period + 0.1)
if msg is None:
break
messages.append(msg)

delta_t = messages[-1].timestamp - messages[0].timestamp
assert delta_t <= duration
def test_send_periodic_duration(self):
"""
Verify that send_periodic only transmits for the specified duration.
Regression test for #1713.
"""
for params in [(0.01, 0.003), (0.1, 0.011), (1, 0.4)]:
duration, period = params
messages = []

self.bus2.send_periodic(can.Message(), period, duration)
while (msg := self.bus1.recv(period * 1.25)) is not None:
messages.append(msg)

delta_t = messages[-1].timestamp - messages[0].timestamp
assert delta_t <= duration


@unittest.skipUnless(TEST_INTERFACE_SOCKETCAN, "skip testing of socketcan")
Expand Down

0 comments on commit 9469332

Please sign in to comment.