@@ -1371,40 +1371,6 @@ async def test_choose_replica_raises_backpressure(
13711371 async with router .choose_replica (request_metadata ):
13721372 pass
13731373
1374- async def test_basic_choose_and_dispatch (
1375- self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
1376- ):
1377- """Test basic choose_replica() and dispatch() workflow."""
1378- router , fake_request_router = setup_router
1379-
1380- r1_id = ReplicaID (
1381- unique_id = "test-replica-1" , deployment_id = DeploymentID (name = "test" )
1382- )
1383- replica = FakeReplica (r1_id )
1384- fake_request_router .set_replica_to_return (replica )
1385-
1386- request_metadata = RequestMetadata (
1387- request_id = "test-request-1" ,
1388- internal_request_id = "test-internal-request-1" ,
1389- call_method = "test_method" ,
1390- )
1391-
1392- # Choose replica
1393- async with router .choose_replica (request_metadata ) as selection :
1394- # Verify selection contains correct information
1395- assert selection .replica_id == r1_id .unique_id
1396- assert selection ._replica == replica
1397- assert selection ._method_name == "test_method"
1398- assert selection ._slot_token in replica ._reserved_slots
1399-
1400- # Dispatch request
1401- replica_result = await router .dispatch (selection , request_metadata )
1402- assert replica_result ._replica_id == r1_id
1403- assert not replica_result ._is_generator_object
1404-
1405- # After context exit, slot should be released
1406- assert selection ._slot_token not in replica ._reserved_slots
1407-
14081374 async def test_choose_without_dispatch_releases_slot (
14091375 self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
14101376 ):
@@ -1459,12 +1425,14 @@ async def test_choose_with_exception_releases_slot(
14591425 assert slot_token not in replica ._reserved_slots
14601426
14611427 @pytest .mark .parametrize ("is_streaming" , [False , True ])
1462- async def test_choose_and_dispatch_streaming (
1428+ async def test_choose_and_dispatch (
14631429 self ,
14641430 setup_router : Tuple [AsyncioRouter , FakeRequestRouter ],
14651431 is_streaming : bool ,
14661432 ):
1467- """Test choose_replica() and dispatch() with streaming requests."""
1433+ """Happy path: selection fields are populated, dispatch sends with
1434+ with_rejection=False (slot reservation replaces the rejection
1435+ round-trip), and the slot is released on exit."""
14681436 router , fake_request_router = setup_router
14691437
14701438 r1_id = ReplicaID (
@@ -1476,45 +1444,23 @@ async def test_choose_and_dispatch_streaming(
14761444 request_metadata = RequestMetadata (
14771445 request_id = "test-request-1" ,
14781446 internal_request_id = "test-internal-request-1" ,
1447+ call_method = "test_method" ,
14791448 is_streaming = is_streaming ,
14801449 )
14811450
14821451 async with router .choose_replica (request_metadata ) as selection :
1483- replica_result = await router .dispatch (selection , request_metadata )
1484- assert replica_result ._replica_id == r1_id
1485- if is_streaming :
1486- assert replica_result ._is_generator_object
1487- else :
1488- assert not replica_result ._is_generator_object
1489-
1490- async def test_slot_reservation_mock_interaction (
1491- self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
1492- ):
1493- """Test that reserve_slot and send_request_with_slot are called correctly."""
1494- router , fake_request_router = setup_router
1495-
1496- r1_id = ReplicaID (
1497- unique_id = "test-replica-1" , deployment_id = DeploymentID (name = "test" )
1498- )
1499- replica = FakeReplica (r1_id )
1500- fake_request_router .set_replica_to_return (replica )
1501-
1502- request_metadata = RequestMetadata (
1503- request_id = "test-request-1" ,
1504- internal_request_id = "test-internal-request-1" ,
1505- )
1506-
1507- # Track initial state
1508- initial_slot_count = replica ._slot_counter
1509-
1510- async with router .choose_replica (request_metadata ) as selection :
1511- # Verify reserve_slot was called
1512- assert replica ._slot_counter == initial_slot_count + 1
1513- assert len (replica ._reserved_slots ) == 1
1452+ assert selection .replica_id == r1_id .unique_id
1453+ assert selection ._replica == replica
1454+ assert selection ._method_name == "test_method"
1455+ assert selection ._slot_token in replica ._reserved_slots
15141456
1515- # Dispatch and verify send_request_with_slot works
15161457 replica_result = await router .dispatch (selection , request_metadata )
15171458 assert replica_result ._replica_id == r1_id
1459+ assert replica_result ._is_generator_object == is_streaming
1460+
1461+ assert selection ._slot_token not in replica ._reserved_slots
1462+ assert len (replica ._requests_sent ) == 1
1463+ assert replica ._requests_sent [0 ]["with_rejection" ] is False
15181464
15191465 async def test_multiple_sequential_selections (
15201466 self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
@@ -1810,36 +1756,6 @@ async def test_dispatch_replica_unavailable(
18101756 with pytest .raises (ReplicaUnavailableError ):
18111757 await router .dispatch (selection , request_metadata )
18121758
1813- async def test_dispatch_uses_reserved_slot (
1814- self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
1815- ):
1816- """Test that dispatch() sends request using reserved slot without rejection."""
1817- router , fake_request_router = setup_router
1818-
1819- r1_id = ReplicaID (
1820- unique_id = "test-replica-1" , deployment_id = DeploymentID (name = "test" )
1821- )
1822- replica = FakeReplica (r1_id )
1823- fake_request_router .set_replica_to_return (replica )
1824-
1825- request_metadata = RequestMetadata (
1826- request_id = "test-request-1" ,
1827- internal_request_id = "test-internal-request-1" ,
1828- )
1829-
1830- async with router .choose_replica (request_metadata ) as selection :
1831- # Verify no requests sent yet
1832- assert len (replica ._requests_sent ) == 0
1833-
1834- # Dispatch the request
1835- replica_result = await router .dispatch (selection , request_metadata )
1836- assert replica_result ._replica_id == r1_id
1837-
1838- # Verify request was sent with with_rejection=False
1839- assert len (replica ._requests_sent ) == 1
1840- assert replica ._requests_sent [0 ]["request_id" ] == "test-request-1"
1841- assert replica ._requests_sent [0 ]["with_rejection" ] is False
1842-
18431759 async def test_multiple_dispatch_calls_fail (
18441760 self , setup_router : Tuple [AsyncioRouter , FakeRequestRouter ]
18451761 ):
0 commit comments