Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 0299aaa

Browse files
committed
initial commit
1 parent 5ada192 commit 0299aaa

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

tests/test_stream_ops.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from streamstore.utils import metered_bytes
1818

1919

20-
@pytest.mark.asyncio(loop_scope="session")
2120
@pytest.mark.stream
2221
class TestStreamOperations:
2322
async def test_check_tail_empty_stream(self, stream: Stream):
@@ -64,24 +63,24 @@ async def test_append_with_match_seq_num(self, stream: Stream):
6463
assert output_1.next_seq_num == 2
6564

6665
async def test_append_with_timestamp(self, stream: Stream):
67-
timestamp_1 = int(time.time())
66+
timestamp_0 = int(time.time())
6867
await asyncio.sleep(0.1)
69-
timestamp_2 = int(time.time())
68+
timestamp_1 = int(time.time())
7069

7170
input = AppendInput(
7271
records=[
73-
Record(body=b"record-0", timestamp=timestamp_1),
74-
Record(body=b"record-1", timestamp=timestamp_2),
72+
Record(body=b"record-0", timestamp=timestamp_0),
73+
Record(body=b"record-1", timestamp=timestamp_1),
7574
]
7675
)
7776
output = await stream.append(input)
7877

7978
assert output.start_seq_num == 0
80-
assert output.start_timestamp == timestamp_1
79+
assert output.start_timestamp == timestamp_0
8180
assert output.end_seq_num == 2
82-
assert output.end_timestamp == timestamp_2
81+
assert output.end_timestamp == timestamp_1
8382
assert output.next_seq_num == 2
84-
assert output.last_timestamp == timestamp_2
83+
assert output.last_timestamp == timestamp_1
8584

8685
async def test_read_from_seq_num_zero(self, stream: Stream):
8786
await stream.append(
@@ -133,6 +132,29 @@ async def test_read_from_tail_offset(self, stream: Stream):
133132
assert records[0].body == b"record-3"
134133
assert records[1].body == b"record-4"
135134

135+
async def test_read_until_timestamp(self, stream: Stream):
136+
timestamp_0 = int(time.time() * 1000)
137+
await asyncio.sleep(0.2)
138+
timestamp_1 = int(time.time() * 1000)
139+
await asyncio.sleep(0.2)
140+
timestamp_2 = int(time.time() * 1000)
141+
142+
await stream.append(
143+
AppendInput(
144+
records=[
145+
Record(body=b"record-0", timestamp=timestamp_0),
146+
Record(body=b"record-1", timestamp=timestamp_1),
147+
Record(body=b"record-2", timestamp=timestamp_2),
148+
]
149+
)
150+
)
151+
152+
records = await stream.read(start=Timestamp(timestamp_0), until=timestamp_2)
153+
assert isinstance(records, list)
154+
assert len(records) == 2
155+
assert records[0].timestamp == timestamp_0
156+
assert records[1].timestamp == timestamp_1
157+
136158
async def test_read_beyond_tail(self, stream: Stream):
137159
await stream.append(
138160
AppendInput(records=[Record(body=f"record-{i}".encode()) for i in range(5)])
@@ -188,7 +210,9 @@ async def producer():
188210
producer_task = asyncio.create_task(producer())
189211

190212
try:
191-
async for output in stream.read_session(start=SeqNum(tail.next_seq_num)):
213+
async for output in stream.read_session(
214+
start=SeqNum(tail.next_seq_num), clamp=True
215+
):
192216
if isinstance(output, list) and len(output) > 0:
193217
assert output[0].body == b"record-0"
194218
break

0 commit comments

Comments
 (0)