Skip to content

Commit e7653b5

Browse files
committed
add tmp test
1 parent 6e351aa commit e7653b5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/unit_tests/test_router.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,54 @@ async def test_independent_batchers_and_routers_per_endpoint():
325325

326326
finally:
327327
await service.shutdown()
328+
329+
330+
@pytest.mark.timeout(10)
331+
@pytest.mark.asyncio
332+
async def test_rr_batch_incr_bsize5_behaves_like_normal_incr():
333+
"""Ensure rr_batch_incr_bsize5 (batch_size=5) behaves like a normal incr endpoint for single calls."""
334+
service = await Counter.options(procs=1, num_replicas=1).as_service(v=5)
335+
336+
try:
337+
# Initial value
338+
assert await service.value.route() == 5
339+
340+
# Call batched increment once
341+
await service.rr_batch_incr_bsize5.route()
342+
343+
# Should increment exactly once
344+
assert await service.value.route() == 6
345+
346+
finally:
347+
await service.shutdown()
348+
349+
350+
@pytest.mark.asyncio
351+
async def test_service_endpoint_batching_preserves_order():
352+
class MyActor(ForgeActor):
353+
def __init__(self):
354+
self._num_calls = 0
355+
self._sum = 0
356+
357+
@endpoint
358+
async def get_num_calls(self):
359+
return self._num_calls
360+
361+
@endpoint
362+
async def get_sum(self):
363+
return self._sum
364+
365+
@service_endpoint(router=RoundRobinRouter, batch_size=5, batch_timeout=0.05)
366+
async def test(self, inputs: list[int]):
367+
self._num_calls += 1
368+
self._sum += sum(inputs)
369+
return inputs
370+
371+
service = await MyActor.options(num_replicas=2, procs=1).as_service()
372+
try:
373+
results = await asyncio.gather(*[service.test.route(i) for i in range(5)])
374+
assert results == [0, 1, 2, 3, 4]
375+
assert await service.get_num_calls.route() == 1
376+
assert sorted(await service.get_sum.fanout()) == [0, 10]
377+
finally:
378+
await service.shutdown()

0 commit comments

Comments
 (0)