Record pathfinding context on flying disconnects
This commit is contained in:
1 parent
0b462f4a76
commit
d4eae5ee5f
5 files changed
+141
-2
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import importlib.util
|
||||
from contextlib import redirect_stdout
|
||||
import io
|
||||
from pathlib import Path
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -38,6 +41,25 @@ class FakeConnection:
|
||||
|
||||
|
||||
class ConnectionShutdownTests(unittest.TestCase):
|
||||
def test_flying_disconnect_reports_active_pathfinding_duration(self):
|
||||
started_at = time.monotonic() - 0.5
|
||||
state = Munch(pathfinding_active={42: {
|
||||
'started_at': started_at, 'timeout': 2.0,
|
||||
'start': (0, 64, 0), 'goal': (5, 64, 0),
|
||||
'thread': 'mosfet-movement',
|
||||
}}, pathfinding_history=[])
|
||||
packet = Munch(reason={'translate': 'multiplayer.disconnect.flying'})
|
||||
output = io.StringIO()
|
||||
|
||||
with redirect_stdout(output):
|
||||
connect._log_flying_pathfinding(state, packet)
|
||||
|
||||
logged = output.getvalue()
|
||||
self.assertIn('[pathfinding] flying disconnect diagnostics', logged)
|
||||
self.assertIn('active for', logged)
|
||||
self.assertIn('(0, 64, 0) -> (5, 64, 0)', logged)
|
||||
self.assertIn('mosfet-movement', logged)
|
||||
|
||||
def test_ctrl_c_stops_connection_retry_loop(self):
|
||||
state = Munch(running=True)
|
||||
connections = []
|
||||
|
||||
@@ -87,6 +87,20 @@ class DoorNavigationTests(unittest.TestCase):
|
||||
with self.assertRaises(AStarTimeout):
|
||||
finder.neighbors((0, 64, 0))
|
||||
|
||||
def test_pathfinder_records_completed_search_duration(self):
|
||||
g = Munch(chunks=FakeChunks({}), crawling=False,
|
||||
unopenable_doors=set())
|
||||
route = Pathfinder(g).astar((0, 64, 0), (0, 64, 0))
|
||||
|
||||
self.assertEqual(route, [(0, 64, 0)])
|
||||
self.assertEqual(g.pathfinding_active, {})
|
||||
self.assertEqual(len(g.pathfinding_history), 1)
|
||||
record = g.pathfinding_history[0]
|
||||
self.assertEqual(record['start'], (0, 64, 0))
|
||||
self.assertEqual(record['goal'], (0, 64, 0))
|
||||
self.assertEqual(record['status'], 'found')
|
||||
self.assertGreaterEqual(record['duration'], 0.0)
|
||||
|
||||
def test_path_prefix_detects_new_obstacles_and_missing_support(self):
|
||||
class TerrainChunks:
|
||||
def __init__(self):
|
||||
|
||||
Reference in new issue
Block a user