Feat/producer unit tests#12
Merged
Merged
Conversation
This commit introduces a comprehensive suite of unit tests for the `producer.rs` binary.
Key changes include:
1. **Refactoring for Testability:**
* The `Args` struct was moved from `src/bin/producer.rs` to `src/config.rs` to allow its use in both the binary and test modules.
* The core logic functions `publish_tasks` and `aggregate_results` were moved from `src/bin/producer.rs` to a new library module `src/producer_logic.rs`.
* Introduced `TaskPublisherChannel` and `ResultConsumerChannel` traits in `src/producer_logic.rs` to abstract `lapin::Channel` operations. This allows mocking these operations during testing.
* `publish_tasks` and `aggregate_results` were made generic over these new traits.
2. **Mocking Infrastructure:**
* Added `mock_lapin` module within `src/tests/producer_tests.rs`.
* `MockChannel` now implements `lapin::Channel` (base trait), `TaskPublisherChannel`, and `ResultConsumerChannel` to simulate RabbitMQ interactions.
* `MockConsumer` struct created to simulate `lapin::Consumer` behavior for `aggregate_results` tests.
3. **Unit Tests Added:**
* **Argument Parsing (`args_tests`):** Tests for `clap` argument parsing, including default values and error conditions.
* **`publish_tasks` (`publish_tasks_tests`):**
* Successful publishing of tasks.
* Handling of Parquet reading errors.
* Handling of RabbitMQ queue declaration and publish errors.
* Behavior with empty input files.
* **`aggregate_results` (`aggregate_results_tests`):**
* Successful aggregation of results (both `Success` and `Filtered` outcomes).
* Verification of output Parquet file contents.
* Handling of RabbitMQ queue declaration and consume errors.
* Handling of message deserialization errors and stream errors during consumption.
* Behavior with no expected results (`published_count = 0`).
4. **Test Utilities:**
* Helper functions in `src/tests/producer_tests.rs` for creating temporary Parquet files with `TextDocument` and `ProcessingOutcome` data.
* Helper function to create mock `lapin::message::Delivery` objects.
This work significantly improves the robustness and maintainability of the producer binary by ensuring its core components are well-tested.
…ub modules depending on config usage (e.g. pipeline)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.