Skip to content

Commit af5c776

Browse files
committed
test(pulsar): add the §5 conformance runner
1 parent a53baa2 commit af5c776

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/test_pulsar_conformance.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Apache Pulsar binding conformance: the vendored manifest's ``pulsar`` block locks the §5
2+
property projection (bq-* string->string) and the ``attempts = max(body, redelivery_count)``
3+
reconciliation (no -1, Pulsar's redelivery count is 0-based). No pulsar-client, no broker —
4+
pure transport logic against golden values."""
5+
6+
from __future__ import annotations
7+
8+
import json
9+
import os
10+
import unittest
11+
12+
from babelqueue import EnvelopeCodec
13+
from babelqueue.pulsar_transport import PulsarTransport
14+
15+
CONFORMANCE = os.path.join(os.path.dirname(__file__), "conformance")
16+
17+
18+
class PulsarConformanceTest(unittest.TestCase):
19+
@classmethod
20+
def setUpClass(cls) -> None:
21+
with open(os.path.join(CONFORMANCE, "manifest.json"), encoding="utf-8") as fh:
22+
cls.pulsar = json.load(fh)["pulsar"]
23+
24+
def test_property_projection(self) -> None:
25+
projection = self.pulsar["property_projection"]
26+
with open(os.path.join(CONFORMANCE, projection["envelope_file"]), encoding="utf-8") as fh:
27+
body = fh.read()
28+
29+
got = PulsarTransport._projection(body)
30+
self.assertEqual(got, projection["properties"])
31+
32+
def test_attempts_reconciliation(self) -> None:
33+
for case in self.pulsar["attempts_reconciliation"]["cases"]:
34+
env = EnvelopeCodec.make("urn:babel:orders:created", {"x": 1})
35+
env["attempts"] = case["body_attempts"]
36+
body = EnvelopeCodec.encode(env)
37+
38+
out = PulsarTransport._reconcile(body, case["redelivery_count"])
39+
40+
self.assertEqual(
41+
EnvelopeCodec.decode(out)["attempts"],
42+
case["expected_attempts"],
43+
case["name"],
44+
)
45+
46+
47+
if __name__ == "__main__": # pragma: no cover
48+
unittest.main()

0 commit comments

Comments
 (0)