connector: wanted(port) says whether anyone watches or reads a port
This commit is contained in:
@@ -306,3 +306,29 @@ def test_a_connector_publishes_bytes_as_a_media_reference(tmp_path):
|
||||
# point of a media dtype.
|
||||
MessageSpec(name="demo.frame", dtype=DType.IMAGE).check(reference)
|
||||
assert store.path(reference["digest"]).read_bytes() == b"\x89PNG..."
|
||||
|
||||
|
||||
def test_a_port_is_wanted_while_watched_or_read(monkeypatch):
|
||||
"""A camera fetches frames only while a screen shows them or a flow reads them."""
|
||||
from fluksio.flow.demand import demand
|
||||
|
||||
node = a_sensor([])
|
||||
# A worker process binds no controller and cannot see who watches.
|
||||
assert node.wanted("reading")
|
||||
|
||||
reads: set[str] = set()
|
||||
monkeypatch.setattr(
|
||||
demand, "_controller", SimpleNamespace(consumed_messages=lambda: reads)
|
||||
)
|
||||
assert not node.wanted("reading")
|
||||
|
||||
reads.add("demo.reading")
|
||||
assert node.wanted("reading")
|
||||
|
||||
reads.clear()
|
||||
demand.want("a viewer", {"demo.reading"})
|
||||
try:
|
||||
assert node.wanted("reading")
|
||||
finally:
|
||||
demand.drop("a viewer")
|
||||
assert not node.wanted("reading")
|
||||
|
||||
Reference in New Issue
Block a user