From 3dbf02f803235312639be15c078ea6c795af5100 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 19 Jul 2026 14:45:26 -0700 Subject: [PATCH] cereal: gc dead ZMQ branches in tests --- .../cereal/messaging/tests/test_messaging.py | 36 ++++--------------- .../messaging/tests/test_pub_sub_master.py | 16 +-------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/openpilot/cereal/messaging/tests/test_messaging.py b/openpilot/cereal/messaging/tests/test_messaging.py index c2ac1578d..92d77f1b3 100644 --- a/openpilot/cereal/messaging/tests/test_messaging.py +++ b/openpilot/cereal/messaging/tests/test_messaging.py @@ -1,4 +1,3 @@ -import os import capnp import multiprocessing import numbers @@ -6,7 +5,6 @@ import random import threading import time from openpilot.common.parameterized import parameterized -import pytest from openpilot.cereal import log from opendbc.car.structs import car @@ -24,10 +22,6 @@ def random_socks(num_socks=10): def random_bytes(length=1000): return bytes([random.randrange(0xFF) for _ in range(length)]) -def zmq_sleep(t=1): - if "ZMQ" in os.environ: - time.sleep(t) - # TODO: this should take any capnp struct and returrn a msg with random populated data def random_carstate(): @@ -53,16 +47,6 @@ def delayed_send(delay, sock, dat): class TestMessaging: - def setUp(self): - # TODO: ZMQ tests are too slow; all sleeps will need to be - # replaced with logic to block on the necessary condition - if "ZMQ" in os.environ: - pytest.skip() - - # ZMQ pub socket takes too long to die - # sleep to prevent multiple publishers error between tests - zmq_sleep() - @parameterized.expand(events) def test_new_message(self, evt): try: @@ -89,7 +73,6 @@ class TestMessaging: sock = "carState" pub_sock = messaging.pub_sock(sock) sub_sock = messaging.sub_sock(sock, timeout=1000) - zmq_sleep() # no wait and no msgs in queue msgs = func(sub_sock) @@ -110,7 +93,6 @@ class TestMessaging: sock = "carState" pub_sock = messaging.pub_sock(sock) sub_sock = messaging.sub_sock(sock, timeout=100) - zmq_sleep() # no wait and no msg in queue, socket should timeout recvd = messaging.recv_sock(sub_sock) @@ -129,7 +111,6 @@ class TestMessaging: sock = "carState" pub_sock = messaging.pub_sock(sock) sub_sock = messaging.sub_sock(sock, timeout=1000) - zmq_sleep() # no msg in queue, socket should timeout recvd = messaging.recv_one(sub_sock) @@ -142,12 +123,10 @@ class TestMessaging: assert isinstance(recvd, capnp._DynamicStructReader) assert_carstate(msg.carState, recvd.carState) - @pytest.mark.xfail(condition="ZMQ" in os.environ, reason='ZMQ detected') def test_recv_one_or_none(self): sock = "carState" pub_sock = messaging.pub_sock(sock) sub_sock = messaging.sub_sock(sock) - zmq_sleep() # no msg in queue, socket shouldn't block recvd = messaging.recv_one_or_none(sub_sock) @@ -165,16 +144,13 @@ class TestMessaging: sock_timeout = 0.1 pub_sock = messaging.pub_sock(sock) sub_sock = messaging.sub_sock(sock, timeout=round(sock_timeout*1000)) - zmq_sleep() - # this test doesn't work with ZMQ since multiprocessing interrupts it - if "ZMQ" not in os.environ: - # wait 5 socket timeouts and make sure it's still retrying - p = multiprocessing.Process(target=messaging.recv_one_retry, args=(sub_sock,)) - p.start() - time.sleep(sock_timeout*5) - assert p.is_alive() - p.terminate() + # wait 5 socket timeouts and make sure it's still retrying + p = multiprocessing.Process(target=messaging.recv_one_retry, args=(sub_sock,)) + p.start() + time.sleep(sock_timeout*5) + assert p.is_alive() + p.terminate() # wait 5 socket timeouts before sending msg = random_carstate() diff --git a/openpilot/cereal/messaging/tests/test_pub_sub_master.py b/openpilot/cereal/messaging/tests/test_pub_sub_master.py index 20ff855fd..90e78ef64 100644 --- a/openpilot/cereal/messaging/tests/test_pub_sub_master.py +++ b/openpilot/cereal/messaging/tests/test_pub_sub_master.py @@ -5,18 +5,12 @@ from collections.abc import Sized import openpilot.cereal.messaging as messaging from openpilot.cereal.messaging.tests.test_messaging import events, random_sock, random_socks, \ - random_bytes, random_carstate, assert_carstate, \ - zmq_sleep + random_bytes, random_carstate, assert_carstate from openpilot.cereal.services import SERVICE_LIST class TestSubMaster: - def setup_method(self): - # ZMQ pub socket takes too long to die - # sleep to prevent multiple publishers error between tests - zmq_sleep(3) - def test_init(self): sm = messaging.SubMaster(events) for p in [sm.updated, sm.recv_time, sm.recv_frame, sm.alive, @@ -43,7 +37,6 @@ class TestSubMaster: sock = "carState" pub_sock = messaging.pub_sock(sock) sm = messaging.SubMaster([sock,]) - zmq_sleep() msg = random_carstate() pub_sock.send(msg.to_bytes()) @@ -55,7 +48,6 @@ class TestSubMaster: sock = "carState" pub_sock = messaging.pub_sock(sock) sm = messaging.SubMaster([sock,]) - zmq_sleep() for i in range(10): msg = messaging.new_message(sock) @@ -126,11 +118,6 @@ class TestSubMaster: class TestPubMaster: - def setup_method(self): - # ZMQ pub socket takes too long to die - # sleep to prevent multiple publishers error between tests - zmq_sleep(3) - def test_init(self): messaging.PubMaster(events) @@ -138,7 +125,6 @@ class TestPubMaster: socks = random_socks() pm = messaging.PubMaster(socks) sub_socks = {s: messaging.sub_sock(s, conflate=True, timeout=1000) for s in socks} - zmq_sleep() # PubMaster accepts either a capnp msg builder or bytes for capnp in [True, False]: