11import uuid
22
3- import pytest
4- from natsrpy import Nats
53from natsrpy .js import (
64 AckPolicy ,
75 DeliverPolicy ,
1513)
1614
1715
18- @pytest .fixture ()
19- async def js (nats : Nats ) -> JetStream :
20- return await nats .jetstream ()
21-
22-
2316async def test_pull_consumer_create (js : JetStream ) -> None :
2417 stream_name = f"test-pcreate-{ uuid .uuid4 ()} "
2518 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
@@ -40,7 +33,7 @@ async def test_pull_consumer_fetch_with_ack(js: JetStream) -> None:
4033 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
4134 stream = await js .streams .create (config )
4235 try :
43- await js .publish (subj , b"ack-msg" )
36+ await js .publish (subj , b"ack-msg" , wait = True )
4437
4538 consumer_config = PullConsumerConfig (
4639 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -60,7 +53,7 @@ async def test_pull_consumer_nack(js: JetStream) -> None:
6053 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
6154 stream = await js .streams .create (config )
6255 try :
63- await js .publish (subj , b"nack-msg" )
56+ await js .publish (subj , b"nack-msg" , wait = True )
6457
6558 consumer_config = PullConsumerConfig (
6659 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -80,7 +73,7 @@ async def test_pull_consumer_term(js: JetStream) -> None:
8073 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
8174 stream = await js .streams .create (config )
8275 try :
83- await js .publish (subj , b"term-msg" )
76+ await js .publish (subj , b"term-msg" , wait = True )
8477
8578 consumer_config = PullConsumerConfig (
8679 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -100,7 +93,7 @@ async def test_pull_consumer_progress(js: JetStream) -> None:
10093 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
10194 stream = await js .streams .create (config )
10295 try :
103- await js .publish (subj , b"progress-msg" )
96+ await js .publish (subj , b"progress-msg" , wait = True )
10497
10598 consumer_config = PullConsumerConfig (
10699 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -121,7 +114,7 @@ async def test_pull_consumer_message_properties(js: JetStream) -> None:
121114 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
122115 stream = await js .streams .create (config )
123116 try :
124- await js .publish (subj , b"prop-msg" )
117+ await js .publish (subj , b"prop-msg" , wait = True )
125118
126119 consumer_name = f"consumer-{ uuid .uuid4 ()} "
127120 consumer_config = PullConsumerConfig (name = consumer_name )
@@ -149,8 +142,8 @@ async def test_pull_consumer_with_filter_subject(js: JetStream) -> None:
149142 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
150143 stream = await js .streams .create (config )
151144 try :
152- await js .publish (f"{ stream_name } .a" , b"msg-a" )
153- await js .publish (f"{ stream_name } .b" , b"msg-b" )
145+ await js .publish (f"{ stream_name } .a" , b"msg-a" , wait = True )
146+ await js .publish (f"{ stream_name } .b" , b"msg-b" , wait = True )
154147
155148 consumer_config = PullConsumerConfig (
156149 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -171,8 +164,8 @@ async def test_pull_consumer_deliver_policy(js: JetStream) -> None:
171164 config = StreamConfig (name = stream_name , subjects = [f"{ stream_name } .>" ])
172165 stream = await js .streams .create (config )
173166 try :
174- await js .publish (subj , b"old-msg" )
175- await js .publish (subj , b"new-msg" )
167+ await js .publish (subj , b"old-msg" , wait = True )
168+ await js .publish (subj , b"new-msg" , wait = True )
176169
177170 consumer_config = PullConsumerConfig (
178171 name = f"consumer-{ uuid .uuid4 ()} " ,
@@ -243,7 +236,7 @@ async def test_pull_consumer_messages(js: JetStream) -> None:
243236 stream = await js .streams .create (config )
244237 try :
245238 for message in messages :
246- await js .publish (subj , message )
239+ await js .publish (subj , message , wait = True )
247240 consumer_config = PullConsumerConfig (name = f"consumer-{ uuid .uuid4 ()} " )
248241 consumer = await stream .consumers .create (consumer_config )
249242 msgs_iter = await consumer .fetch (timeout = 0.5 )
@@ -261,7 +254,7 @@ async def test_push_consumer_messages(js: JetStream) -> None:
261254 stream = await js .streams .create (config )
262255 try :
263256 for message in messages :
264- await js .publish (subj , message )
257+ await js .publish (subj , message , wait = True )
265258
266259 deliver_subj = uuid .uuid4 ().hex
267260 consumer_config = PushConsumerConfig (
0 commit comments