Skip to content

Commit

Permalink
Do not skip too much
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Apr 26, 2024
1 parent c43ff9e commit 24b2c9a
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions posttroll/tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@

import posttroll
from posttroll import config
from posttroll.message import Message
from posttroll.ns import NameServer
from posttroll.publisher import Publisher, create_publisher_from_dict_config
from posttroll.publisher import Publish, Publisher, create_publisher_from_dict_config
from posttroll.subscriber import Subscribe, Subscriber

test_lock = Lock()
Expand Down Expand Up @@ -85,10 +86,7 @@ def create_nameserver_instance(max_age=3, multicast_enabled=True):
ns.stop()
thr.join()

@pytest.mark.skipif(
os.getenv("DISABLED_MULTICAST"),
reason="Multicast tests disabled.",
)

@pytest.mark.parametrize(
"multicast_enabled",
[True, False]
Expand All @@ -99,6 +97,8 @@ def test_pub_addresses(multicast_enabled):
from posttroll.publisher import Publish

if multicast_enabled:
if os.getenv("DISABLED_MULTICAST"):
pytest.skip("Multicast tests disabled.")
nameservers = None
else:
nameservers = ["localhost"]
Expand Down Expand Up @@ -126,25 +126,21 @@ def test_pub_addresses(multicast_enabled):
assert "receive_time" in res[0]
assert "URI" in res[0]

# @pytest.mark.skipif(
# os.getenv("DISABLED_MULTICAST"),
# reason="Multicast tests disabled.",
# )

@pytest.mark.parametrize(
"multicast_enabled",
[True, False]
)
def test_pub_sub_ctx(multicast_enabled):
"""Test publish and subscribe."""
from posttroll.message import Message
from posttroll.publisher import Publish
from posttroll.subscriber import Subscribe
if multicast_enabled:
if os.getenv("DISABLED_MULTICAST"):
pytest.skip("Multicast tests disabled.")
nameservers = None
else:
nameservers = ["localhost"]

with create_nameserver_instance(multicast_enabled=multicast_enabled):
if multicast_enabled:
nameservers = None
else:
nameservers = ["localhost"]
with Publish("data_provider", 0, ["this_data"], nameservers=nameservers, broadcast_interval=0.1) as pub:
with Subscribe("this_data", "counter") as sub:
for counter in range(5):
Expand All @@ -159,26 +155,21 @@ def test_pub_sub_ctx(multicast_enabled):
assert tested


@pytest.mark.skipif(
os.getenv("DISABLED_MULTICAST"),
reason="Multicast tests disabled.",
)
@pytest.mark.parametrize(
"multicast_enabled",
[True, False]
)
def test_pub_sub_add_rm(multicast_enabled):
"""Test adding and removing publishers."""
from posttroll.publisher import Publish
from posttroll.subscriber import Subscribe

max_age = 0.5

if multicast_enabled:
if os.getenv("DISABLED_MULTICAST"):
pytest.skip("Multicast tests disabled.")
nameservers = None
else:
nameservers = ["localhost"]

max_age = 0.5

with create_nameserver_instance(max_age=max_age, multicast_enabled=multicast_enabled):
with Subscribe("this_data", "counter", addr_listener=True, timeout=.2) as sub:
assert len(sub.addresses) == 0
Expand All @@ -190,7 +181,7 @@ def test_pub_sub_add_rm(multicast_enabled):
for msg in sub.recv(.1):
if msg is None:
break
time.sleep(.1)
time.sleep(.3)
assert len(sub.addresses) == 0
with Publish("data_provider_2", 0, ["another_data"], nameservers=nameservers):
time.sleep(.1)
Expand Down

0 comments on commit 24b2c9a

Please sign in to comment.