Skip to content

Commit 78533ac

Browse files
Make publications reliable by default
1 parent 43e201b commit 78533ac

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

cynic.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
HOME = "cynic/" # Trailing slash to generate a unique home.
2828
DEFAULT_TIMEOUT = 10.0
29-
CONSENSUS_SYNC_DELAY = 0.3
3029
SCOUT_PATTERN = "/>"
3130

3231
_logger = logging.getLogger("cynic")
@@ -107,10 +106,9 @@ async def cmd_sub(node: Node, args: argparse.Namespace) -> int:
107106
async def cmd_pub(node: Node, args: argparse.Namespace) -> int:
108107
pubs = [node.advertise(x) for x in args.topic]
109108
try:
110-
await asyncio.sleep(CONSENSUS_SYNC_DELAY)
111109
deadline = Instant.now() + args.timeout
112110
message = unescape(args.data)
113-
await asyncio.gather(*(pub(deadline, message, reliable=args.reliable) for pub in pubs))
111+
await asyncio.gather(*(pub(deadline, message, reliable=True) for pub in pubs))
114112
_logger.info("Published on %s", args.topic)
115113
finally:
116114
for pub in pubs:
@@ -147,7 +145,6 @@ async def request(pub: Publisher, timeout: float, message: bytes) -> int:
147145
async def cmd_req(node: Node, args: argparse.Namespace) -> int:
148146
pubs = [node.advertise(x) for x in args.topic]
149147
try:
150-
await asyncio.sleep(CONSENSUS_SYNC_DELAY)
151148
message = unescape(args.data)
152149
counts = await asyncio.gather(*(request(pub, args.timeout, message) for pub in pubs))
153150
finally:
@@ -224,7 +221,6 @@ def main() -> int:
224221
p_sub.set_defaults(func=cmd_sub)
225222

226223
p_pub = sub.add_parser("pub", help="publish DATA on each TOPIC once")
227-
p_pub.add_argument("-r", "--reliable", action="store_true")
228224
p_pub.add_argument("topic", nargs="+")
229225
p_pub.add_argument("data", help=r"hex-escape-encoded, e.g. 'hello\x0dworld!\n'")
230226
p_pub.set_defaults(func=cmd_pub)

tests/test_cynic.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,22 @@ def test_sub_multiple_topics_independently(tmp_path: Path, link: list[str]) -> N
233233
assert all(payload_eq(by_topic[t], f"msg{i}".encode()) for i, t in enumerate(topics))
234234

235235

236-
def test_pub_reliable_with_subscriber(subscriber: Subscriber, link: list[str], topic: str) -> None:
237-
assert run_cynic(link, "pub", "-r", topic, "ack me").returncode == 0
236+
def test_pub_with_subscriber(subscriber: Subscriber, link: list[str], topic: str) -> None:
237+
assert run_cynic(link, "pub", topic, "ack me").returncode == 0
238238
(msg,) = collect(subscriber.out, 1, SETTLE)
239239
assert payload_eq(cynic.unescape(msg["msg"]), b"ack me")
240240

241241

242242
def test_pub_reliable_without_subscriber(link: list[str], topic: str) -> None:
243-
r = run_cynic(link, "pub", "-r", topic, "nobody home")
243+
r = run_cynic(link, "pub", topic, "nobody home")
244244
assert r.returncode == 1
245245
assert "DeliveryError" in r.stderr
246246

247247

248-
def test_pub_best_effort_without_subscriber(link: list[str], topic: str) -> None:
249-
assert run_cynic(link, "pub", topic, "into the void").returncode == 0
248+
def test_pub_reliability_flag_is_removed(link: list[str], topic: str) -> None:
249+
r = run_cynic(link, "pub", "--reliable", topic, "deprecated")
250+
assert r.returncode == 2
251+
assert "unrecognized arguments: --reliable" in r.stderr
250252

251253

252254
@contextlib.contextmanager

0 commit comments

Comments
 (0)