33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
# Copyright © 2026 Setti Solutions S.R.L, www.setti.md. All rights reserved.
|
|
from cantabile_edge.store import Queue
|
|
|
|
|
|
def test_order_ack_and_no_reuse(tmp_path):
|
|
q = Queue(str(tmp_path / "q.db"), 100)
|
|
seqs = [q.put("tel", {"i": i}) for i in range(5)]
|
|
assert seqs == sorted(seqs)
|
|
assert [p["i"] for _, _, p in q.peek(3)] == [0, 1, 2]
|
|
q.ack(seqs[1])
|
|
assert [s for s, _, _ in q.peek()] == seqs[2:]
|
|
q.ack(seqs[-1])
|
|
assert q.depth() == 0
|
|
assert q.put("tel", {}) > seqs[-1] # a number is never used twice
|
|
|
|
|
|
def test_survives_reopen(tmp_path):
|
|
p = str(tmp_path / "q.db")
|
|
q = Queue(p, 100)
|
|
q.put("tel", {"a": 1})
|
|
q.put("stats", {"b": 2})
|
|
q.close()
|
|
q = Queue(p, 100)
|
|
assert [(k, d) for _, k, d in q.peek()] == [("tel", {"a": 1}), ("stats", {"b": 2})]
|
|
|
|
|
|
def test_bounded_drops_oldest_and_counts(tmp_path):
|
|
q = Queue(str(tmp_path / "q.db"), 3)
|
|
for i in range(5):
|
|
q.put("tel", {"i": i})
|
|
assert [p["i"] for _, _, p in q.peek()] == [2, 3, 4]
|
|
assert q.dropped() == 2
|