Fix self.started value pass in metadrive test (#31153)

* fix value pass

* fix test

---------

Co-authored-by: Justin Newberry <justin@comma.ai>
pull/31281/head
Hoang Bui 1 year ago committed by GitHub
parent 83fc734b8f
commit 71236204bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      tools/sim/bridge/common.py
  2. 3
      tools/sim/tests/test_metadrive_bridge.py
  3. 5
      tools/sim/tests/test_sim_bridge.py

@ -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}")

Loading…
Cancel
Save