File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 66from qstash import AsyncQStash
77from qstash .flow_control_api import GlobalParallelismInfo
88from qstash .message import FlowControl , PublishResponse
9+ from tests import assert_eventually_async
910
1011
1112@pytest .mark .asyncio
@@ -191,12 +192,13 @@ async def test_flow_control_reset_rate_async(async_client: AsyncQStash) -> None:
191192 # Reset the rate
192193 await async_client .flow_control .reset_rate (flow_control_key )
193194
194- # sleep 1 second
195- await asyncio .sleep (1 )
195+ # We use assert_eventually because reset_rate doesn't take effect immediately.
196+ # Not ideal but it's what we have.
197+ async def check_rate_reset () -> None :
198+ info = await async_client .flow_control .get (flow_control_key )
199+ assert info .rate_count == 0
196200
197- # Verify rate was reset by checking the flow control info
198- info = await async_client .flow_control .get (flow_control_key )
199- assert info .rate_count == 0
201+ await assert_eventually_async (check_rate_reset )
200202
201203 # Clean up
202204 await async_client .message .cancel (result .message_id )
Original file line number Diff line number Diff line change 33from qstash import QStash
44from qstash .flow_control_api import GlobalParallelismInfo
55from qstash .message import FlowControl , PublishResponse
6+ from tests import assert_eventually
67
78
89def test_flow_control_get (client : QStash ) -> None :
@@ -180,12 +181,13 @@ def test_flow_control_reset_rate(client: QStash) -> None:
180181 # Reset the rate
181182 client .flow_control .reset_rate (flow_control_key )
182183
183- # sleep 1 second
184- time .sleep (1 )
184+ # We use assert_eventually because reset_rate doesn't take effect immediately.
185+ # Not ideal but it's what we have.
186+ def check_rate_reset () -> None :
187+ info = client .flow_control .get (flow_control_key )
188+ assert info .rate_count == 0
185189
186- # Verify rate was reset by checking the flow control info
187- info = client .flow_control .get (flow_control_key )
188- assert info .rate_count == 0
190+ assert_eventually (check_rate_reset )
189191
190192 # Clean up
191193 client .message .cancel (result .message_id )
You can’t perform that action at this time.
0 commit comments