Skip to content

Commit 9b89271

Browse files
committed
Restructure tests, fix up a few other things, rework smokevirt thoroughly
1 parent 1cd1aed commit 9b89271

6 files changed

Lines changed: 848 additions & 767 deletions

File tree

meshtastic/node.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,22 @@ def deleteChannel(self, channelIndex):
287287
# for sending admin channels will also change
288288
adminIndex = self.iface.localNode._getAdminChannelIndex()
289289

290+
# Snapshot serialized channel payloads from channelIndex onward so we
291+
# can avoid writing slots whose protobuf content did not change after
292+
# the shift. Use bytes (not message objects), because _fixupChannels()
293+
# mutates message fields in-place.
294+
old_channels = [
295+
self.channels[i].SerializeToString()
296+
for i in range(channelIndex, len(self.channels))
297+
]
298+
290299
self.channels.pop(channelIndex)
291300
self._fixupChannels() # expand back to 8 channels
292301

293302
index = channelIndex
294-
while index < 8:
295-
self.writeChannel(index, adminIndex=adminIndex)
303+
for old_ch in old_channels:
304+
if self.channels[index].SerializeToString() != old_ch:
305+
self.writeChannel(index, adminIndex=adminIndex)
296306
index += 1
297307

298308
# if we are updating the local node, we might end up

meshtastic/tests/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919
# Use a different base port for the single-node fixture so it doesn't
20-
# conflict with the multi-node mesh fixture (both are session-scoped).
20+
# conflict with the multi-node mesh fixture.
2121
SINGLE_NODE_BASE_PORT = DEFAULT_BASE_PORT + 100
2222

2323

@@ -31,10 +31,15 @@ def _skip_firmware_if_unavailable() -> None:
3131
)
3232

3333

34-
@pytest.fixture(scope="session")
34+
@pytest.fixture(scope="function")
3535
def firmware_node():
3636
"""A single meshtasticd sim node for smokevirt tests.
3737
38+
Function-scoped so every test gets a freshly-erased node with no
39+
state leaking from previous tests. This makes destructive commands
40+
(``--reboot``, ``--set factory_reset true``) safe to run and lets
41+
tests be order-independent.
42+
3843
Yields the SimNode instance. The node is booted with a fresh erased
3944
config and listens on localhost at its TCP port.
4045
"""

meshtastic/tests/firmware_harness.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def _kill(self) -> None:
161161
os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)
162162
except Exception:
163163
pass
164+
# Give OS time to release TCP port (avoid TIME_WAIT preventing
165+
# next instance from binding the same port)
166+
time.sleep(1.0)
164167
self.process = None
165168

166169

0 commit comments

Comments
 (0)