Skip to content

Refactor RequestGenerator to use threading and update test suite #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

markurtz
Copy link
Member

Refactored RequestGenerator class:

  • Replaced asyncio.Queue with Queue from the queue module for thread safety.
  • Utilized threading for background queue population to ensure non-blocking request generation.
  • Removed the start method as threading automatically starts the background task in async mode.
  • Ensured that the _populate_queue method runs in a background thread to keep the queue populated.
  • Implemented clean shutdown with the stop method joining the background thread. Updated unit tests:
  • Added test_request_generator_sync_constructor and test_request_generator_async_constructor to verify constructor behavior.
  • Added tests for repr and iter methods.
  • Added tests to ensure create_item raises NotImplementedError if not overridden.
  • Added tests to verify iter calls create_item the expected number of times.

Separated test files:

  • Created tests/unit/request/test_base.py for unit tests.
  • Created tests/integration/request/test_base.py for integration tests.

Unit tests:

  • Verified the construction of the class with different input parameters.
  • Mocked AutoTokenizer for testing tokenizer initialization with both a class implementation and a string alias.
  • Ensured that the iter method works correctly in both sync and async modes.
  • Verified that create_item is called the expected number of times.

Integration tests:

  • Tested tokenizer construction with both a Hugging Face tokenizer and a string alias, ensuring the correct tokenizer is created.

Refactored RequestGenerator class:
- Replaced asyncio.Queue with Queue from the queue module for thread safety.
- Utilized threading for background queue population to ensure non-blocking request generation.
- Removed the start method as threading automatically starts the background task in async mode.
- Ensured that the _populate_queue method runs in a background thread to keep the queue populated.
- Implemented clean shutdown with the stop method joining the background thread.
Updated unit tests:
- Added test_request_generator_sync_constructor and test_request_generator_async_constructor to verify constructor behavior.
- Added tests for __repr__ and __iter__ methods.
- Added tests to ensure create_item raises NotImplementedError if not overridden.
- Added tests to verify __iter__ calls create_item the expected number of times.

Separated test files:
- Created tests/unit/request/test_base.py for unit tests.
- Created tests/integration/request/test_base.py for integration tests.

Unit tests:
- Verified the construction of the class with different input parameters.
- Mocked AutoTokenizer for testing tokenizer initialization with both a class implementation and a string alias.
- Ensured that the __iter__ method works correctly in both sync and async modes.
- Verified that create_item is called the expected number of times.

Integration tests:
- Tested tokenizer construction with both a Hugging Face tokenizer and a string alias, ensuring the correct tokenizer is created.
@markurtz markurtz self-assigned this Jun 28, 2024
Copy link
Contributor

@parfeniuklits parfeniuklits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

markurtz and others added 2 commits July 2, 2024 09:30
Co-authored-by: Dmytro Parfeniuk <dmytro.parfeniuk@litslink.com>
@parfeniukink
Copy link
Contributor

@markurtz Might be not related to this PR, but actually the schedule package also contains dependencies on asyncio in its Task

@markurtz markurtz merged commit ff3f695 into main Jul 5, 2024
@markurtz markurtz deleted the request-gen-fixes branch August 21, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants