Skip to content

Commit

Permalink
Make node scanner tests more deterministic (#526)
Browse files Browse the repository at this point in the history
This fixes up the tests added with #517 (commit
d1c28e5).
  • Loading branch information
erlend-aasland authored Aug 11, 2024
1 parent d1c28e5 commit d75c5f0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,28 @@ def test_scanner_search_no_network(self):
self.scanner.search()

def test_scanner_search(self):
bus = can.Bus(interface="virtual", receive_own_messages=True)
net = canopen.Network(bus)
rxbus = can.Bus(interface="virtual")
self.addCleanup(rxbus.shutdown)

txbus = can.Bus(interface="virtual")
self.addCleanup(txbus.shutdown)

net = canopen.Network(txbus)
net.connect()
self.addCleanup(net.disconnect)

self.scanner.network = net
self.scanner.search()

payload = bytes([64, 0, 16, 0, 0, 0, 0, 0])
acc = [bus.recv(self.TIMEOUT) for _ in range(127)]
acc = [rxbus.recv(self.TIMEOUT) for _ in range(127)]
for node_id, msg in enumerate(acc, start=1):
with self.subTest(node_id=node_id):
self.assertIsNotNone(msg)
self.assertEqual(msg.arbitration_id, 0x600 + node_id)
self.assertEqual(msg.data, payload)
# Check that no spurious packets were sent.
self.assertIsNone(bus.recv(self.TIMEOUT))
self.assertIsNone(rxbus.recv(self.TIMEOUT))

def test_scanner_search_limit(self):
bus = can.Bus(interface="virtual", receive_own_messages=True)
Expand Down

0 comments on commit d75c5f0

Please sign in to comment.