Skip to content

Commit e4fea05

Browse files
Upstash Boxclaude
andcommitted
test: add unpin single field test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 74d1353 commit e4fea05

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/asyncio/test_flow_control.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,43 @@ async def test_flow_control_pin_unpin_async(async_client: AsyncQStash) -> None:
133133
await async_client.message.cancel(result.message_id)
134134

135135

136+
@pytest.mark.asyncio
137+
async def test_flow_control_unpin_single_async(async_client: AsyncQStash) -> None:
138+
flow_control_key = f"fc-unpin-single-{int(time.time() * 1000)}"
139+
140+
result = await async_client.message.publish_json(
141+
body={"test": "value"},
142+
url="https://mock.httpstatus.io/200?sleep=30000",
143+
flow_control=FlowControl(
144+
key=flow_control_key,
145+
parallelism=5,
146+
rate=10,
147+
period="1m",
148+
),
149+
)
150+
assert isinstance(result, PublishResponse)
151+
152+
# Pin both parallelism and rate
153+
await async_client.flow_control.pin(
154+
flow_control_key,
155+
{"parallelism": 3, "rate": 20, "period": 120},
156+
)
157+
158+
pinned = await async_client.flow_control.get(flow_control_key)
159+
assert pinned.is_pinned_parallelism is True
160+
assert pinned.is_pinned_rate is True
161+
162+
# Unpin only parallelism
163+
await async_client.flow_control.unpin(flow_control_key, {"parallelism": True})
164+
165+
partial = await async_client.flow_control.get(flow_control_key)
166+
assert partial.is_pinned_parallelism is False
167+
assert partial.is_pinned_rate is True
168+
169+
# Clean up
170+
await async_client.message.cancel(result.message_id)
171+
172+
136173
@pytest.mark.asyncio
137174
async def test_flow_control_reset_rate_async(async_client: AsyncQStash) -> None:
138175
flow_control_key = f"fc-reset-{int(time.time() * 1000)}"

tests/test_flow_control.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,42 @@ def test_flow_control_pin_unpin(client: QStash) -> None:
124124
client.message.cancel(result.message_id)
125125

126126

127+
def test_flow_control_unpin_single(client: QStash) -> None:
128+
flow_control_key = f"fc-unpin-single-{int(time.time() * 1000)}"
129+
130+
result = client.message.publish_json(
131+
body={"test": "value"},
132+
url="https://mock.httpstatus.io/200?sleep=30000",
133+
flow_control=FlowControl(
134+
key=flow_control_key,
135+
parallelism=5,
136+
rate=10,
137+
period="1m",
138+
),
139+
)
140+
assert isinstance(result, PublishResponse)
141+
142+
# Pin both parallelism and rate
143+
client.flow_control.pin(
144+
flow_control_key,
145+
{"parallelism": 3, "rate": 20, "period": 120},
146+
)
147+
148+
pinned = client.flow_control.get(flow_control_key)
149+
assert pinned.is_pinned_parallelism is True
150+
assert pinned.is_pinned_rate is True
151+
152+
# Unpin only parallelism
153+
client.flow_control.unpin(flow_control_key, {"parallelism": True})
154+
155+
partial = client.flow_control.get(flow_control_key)
156+
assert partial.is_pinned_parallelism is False
157+
assert partial.is_pinned_rate is True
158+
159+
# Clean up
160+
client.message.cancel(result.message_id)
161+
162+
127163
def test_flow_control_reset_rate(client: QStash) -> None:
128164
flow_control_key = f"fc-reset-{int(time.time() * 1000)}"
129165

0 commit comments

Comments
 (0)