From aac846eed170329866947bad467334e7a013f6ad Mon Sep 17 00:00:00 2001 From: bhuvan-somisetty Date: Tue, 13 Oct 2026 09:53:30 +0530 Subject: [PATCH] fix: let unchanged() see ZMQ reads in Python --- concore_base.py | 1 + tests/test_concore.py | 16 ++++++++++++++++ tests/test_concoredocker.py | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/concore_base.py b/concore_base.py index 4362424..3ec5878 100644 --- a/concore_base.py +++ b/concore_base.py @@ -275,6 +275,7 @@ def read(mod, port_identifier, name, initstr_val): zmq_p = mod.zmq_ports[port_identifier] try: message = zmq_p.recv_json_with_retry() + mod.s += str(message) # so unchanged() sees the new data # Strip simtime prefix if present (mirroring file-based read behavior) if isinstance(message, list) and len(message) > 0: first_element = message[0] diff --git a/tests/test_concore.py b/tests/test_concore.py index c3096a6..45549ec 100644 --- a/tests/test_concore.py +++ b/tests/test_concore.py @@ -230,6 +230,22 @@ def test_unchanged_returns_false_if_diff(self): assert concore.unchanged() is False assert concore.olds == "new" + def test_unchanged_returns_false_after_zmq_read(self, monkeypatch): + """Issue #612 – a successful ZMQ read must count as new data.""" + import concore + + class DummyPort: + def recv_json_with_retry(self): + return [1.0, 10.0] + + monkeypatch.setitem(concore.zmq_ports, "test_zmq", DummyPort()) + concore.s = "" + concore.olds = "" + + assert concore.unchanged() is True + concore.read("test_zmq", "u", "[0]") + assert concore.unchanged() is False + class TestParseParams: def test_simple_key_value_pairs(self): diff --git a/tests/test_concoredocker.py b/tests/test_concoredocker.py index 15ff939..e602034 100644 --- a/tests/test_concoredocker.py +++ b/tests/test_concoredocker.py @@ -236,6 +236,21 @@ def recv_json_with_retry(self): assert concoredocker.simtime == 5.0 + def test_read_breaks_unchanged(self, monkeypatch): + import concoredocker + + class DummyPort: + def recv_json_with_retry(self): + return [1.0, 10.0] + + concoredocker.zmq_ports["test_zmq"] = DummyPort() + monkeypatch.setattr(concoredocker, "s", "") + monkeypatch.setattr(concoredocker, "olds", "") + + assert concoredocker.unchanged() is True + concoredocker.read("test_zmq", "data", "[0]") + assert concoredocker.unchanged() is False + def test_write_read_roundtrip(self): import concoredocker