Fix self.started value pass in metadrive test (#31153)
* fix value pass * fix test --------- Co-authored-by: Justin Newberry <justin@comma.ai> old-commit-hash: 71236204bb78d64feb3d46680176dfb37741dc5d
This commit is contained in:
@@ -2,7 +2,7 @@ import signal
|
||||
import threading
|
||||
import functools
|
||||
|
||||
from multiprocessing import Process, Queue
|
||||
from multiprocessing import Process, Queue, Value
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
@@ -39,7 +39,7 @@ class SimulatorBridge(ABC):
|
||||
self._exit_event = threading.Event()
|
||||
self._threads = []
|
||||
self._keep_alive = True
|
||||
self.started = False
|
||||
self.started = Value('i', False)
|
||||
signal.signal(signal.SIGTERM, self._on_shutdown)
|
||||
self._exit = threading.Event()
|
||||
self.simulator_state = SimulatorState()
|
||||
@@ -61,7 +61,7 @@ class SimulatorBridge(ABC):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
self.started = False
|
||||
self.started.value = False
|
||||
self._exit_event.set()
|
||||
|
||||
if self.world is not None:
|
||||
@@ -181,6 +181,6 @@ Ignition: {self.simulator_state.ignition} Engaged: {self.simulator_state.is_enga
|
||||
if self.rk.frame % 25 == 0:
|
||||
self.print_status()
|
||||
|
||||
self.started = True
|
||||
self.started.value = True
|
||||
|
||||
self.rk.keep_time()
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from openpilot.tools.sim.run_bridge import parse_args
|
||||
from openpilot.tools.sim.bridge.metadrive.metadrive_bridge import MetaDriveBridge
|
||||
from openpilot.tools.sim.tests.test_sim_bridge import TestSimBridgeBase
|
||||
|
||||
@pytest.mark.slow
|
||||
class TestMetaDriveBridge(TestSimBridgeBase):
|
||||
def create_bridge(self):
|
||||
return MetaDriveBridge(parse_args([]))
|
||||
return MetaDriveBridge(False, False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,7 +3,7 @@ import subprocess
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from multiprocessing import Queue, Value
|
||||
from multiprocessing import Queue
|
||||
|
||||
from cereal import messaging
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
@@ -27,7 +27,6 @@ class TestSimBridgeBase(unittest.TestCase):
|
||||
sm = messaging.SubMaster(['controlsState', 'onroadEvents', 'managerState'])
|
||||
q = Queue()
|
||||
bridge = self.create_bridge()
|
||||
bridge.started = Value('b', False)
|
||||
p_bridge = bridge.run(q, retries=10)
|
||||
self.processes.append(p_bridge)
|
||||
|
||||
@@ -35,7 +34,7 @@ class TestSimBridgeBase(unittest.TestCase):
|
||||
|
||||
# Wait for bridge to startup
|
||||
start_waiting = time.monotonic()
|
||||
while not bridge.started and time.monotonic() < start_waiting + max_time_per_step:
|
||||
while not bridge.started.value and time.monotonic() < start_waiting + max_time_per_step:
|
||||
time.sleep(0.1)
|
||||
self.assertEqual(p_bridge.exitcode, None, f"Bridge process should be running, but exited with code {p_bridge.exitcode}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user