test_request_tracker.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import pytest
  2. from aphrodite.engine.async_aphrodite import RequestTracker
  3. from aphrodite.common.outputs import RequestOutput
  4. @pytest.mark.asyncio
  5. async def test_request_tracker():
  6. tracker = RequestTracker()
  7. stream_1 = tracker.add_request("1")
  8. new, finished = tracker.get_new_and_finished_requests()
  9. assert not tracker.new_requests_event.is_set()
  10. assert len(new) == 1
  11. assert new[0]["request_id"] == "1"
  12. assert not finished
  13. assert not stream_1.finished
  14. stream_2 = tracker.add_request("2")
  15. stream_3 = tracker.add_request("3")
  16. assert tracker.new_requests_event.is_set()
  17. await tracker.wait_for_new_requests()
  18. new, finished = tracker.get_new_and_finished_requests()
  19. assert not tracker.new_requests_event.is_set()
  20. assert len(new) == 2
  21. assert new[0]["request_id"] == "2"
  22. assert new[1]["request_id"] == "3"
  23. assert not finished
  24. assert not stream_2.finished
  25. assert not stream_3.finished
  26. # request_ids must be unique
  27. with pytest.raises(KeyError):
  28. tracker.add_request("1")
  29. assert not tracker.new_requests_event.is_set()
  30. tracker.abort_request("1")
  31. new, finished = tracker.get_new_and_finished_requests()
  32. assert len(finished) == 1
  33. assert "1" in finished
  34. assert not new
  35. assert stream_1.finished
  36. stream_4 = tracker.add_request("4")
  37. tracker.abort_request("4")
  38. assert tracker.new_requests_event.is_set()
  39. await tracker.wait_for_new_requests()
  40. new, finished = tracker.get_new_and_finished_requests()
  41. assert len(finished) == 1
  42. assert "4" in finished
  43. assert not new
  44. assert stream_4.finished
  45. stream_5 = tracker.add_request("5")
  46. assert tracker.new_requests_event.is_set()
  47. tracker.process_request_output(
  48. RequestOutput("2", "output", [], [], [], finished=True))
  49. await tracker.wait_for_new_requests()
  50. new, finished = tracker.get_new_and_finished_requests()
  51. assert not tracker.new_requests_event.is_set()
  52. assert len(finished) == 1
  53. assert "2" in finished
  54. assert len(new) == 1
  55. assert new[0]["request_id"] == "5"
  56. assert stream_2.finished
  57. assert not stream_5.finished