import pytest
import wingfoil as wf
aeron_available = hasattr(wf, "aeron_sub")
requires_binding = pytest.mark.skipif(
not aeron_available,
reason="wingfoil-python built without --features aeron",
)
CHANNEL = "aeron:ipc"
STREAM_ID = 424242
@requires_binding
class TestAeronConstruction:
def test_sub_without_driver_raises(self):
with pytest.raises(Exception):
wf.aeron_sub(CHANNEL, STREAM_ID, timeout_secs=0.5)
def test_sub_mode_argument_is_accepted(self):
with pytest.raises(Exception):
wf.aeron_sub(
CHANNEL, STREAM_ID, mode=wf.AeronMode.Threaded, timeout_secs=0.5
)
def test_pub_method_without_driver_raises(self):
with pytest.raises(Exception):
wf.constant(b"v").aeron_pub(CHANNEL, STREAM_ID, timeout_secs=0.5)
def test_aeron_mode_enum_values(self):
assert wf.AeronMode.Spin != wf.AeronMode.Threaded
@pytest.mark.requires_aeron
class TestAeronRoundTrip:
def test_pub_sub_round_trip_bytes(self):
channel = "aeron:ipc"
stream_id = 770001
sub = wf.aeron_sub(channel, stream_id, mode=wf.AeronMode.Spin)
collected = sub.collect()
pub = wf.ticker(0.02).count().map(lambda _: b"hello").aeron_pub(
channel, stream_id
)
graph = wf.Graph([pub, collected])
graph.run(realtime=True, duration=0.4)
ticks = collected.peek_value()
assert ticks, "expected at least one tick"
values = [item for tick in ticks for item in tick]
assert values, "expected at least one message"
assert all(v == b"hello" for v in values)