Skip to content
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

Write Integration tests #5

Merged
merged 22 commits into from
May 24, 2024
Merged

Conversation

AryanGodara
Copy link
Contributor

@AryanGodara AryanGodara commented Apr 9, 2024

In progress

Summary by CodeRabbit

  • New Features

    • Introduced various test functions and utilities for job operations, database interactions, and server testing.
    • Added new dependencies for mocking and testing purposes.
  • Refactor

    • Refactored configuration initialization into a separate async function.
    • Reorganized imports to use the orchestrator namespace.
  • Enhancements

    • Added PartialEq and PartialOrd derivations to enums for improved comparability.
    • Made struct fields in Config public for better accessibility.
  • Testing

    • Added extensive unit tests and mock implementations for various modules.
    • Introduced new test modules and functions across different components of the application.

Copy link

coderabbitai bot commented Apr 9, 2024

Warning

Rate Limit Exceeded

@apoorvsadana has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 40 minutes and 3 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8384cb0 and c2cd2df.

Walkthrough

The recent changes introduce extensive testing support and dependency enhancements across multiple crates in the project. Key updates include adding mockall for mocking, httpmock for HTTP request simulations, and restructuring the orchestrator crate to support both library and binary configurations. The orchestrator crate also sees significant improvements in configuration handling, job processing, and comprehensive testing modules.

Changes

Files/Paths Change Summaries
Cargo.toml Added httpmock dependency with version 0.7.0.
crates/da_clients/da-client-interface/Cargo.toml Added mockall version 0.12.1 dependency.
crates/da_clients/da-client-interface/src/lib.rs Introduced mockall for mocking in DaClient trait implementation.
crates/orchestrator/Cargo.toml Added library and binary configuration, new dependencies (mockall, starknet-core), and dev dependencies.
crates/orchestrator/src/config.rs Modified imports, changed struct field visibility, and added init_config() function.
crates/orchestrator/src/database/mod.rs Added #[automock] to Database trait.
crates/orchestrator/src/jobs/da_job/mod.rs Added state_update_to_blob_data_works test function.
crates/orchestrator/src/jobs/mod.rs Updated increment_key_in_metadata, added get_u64_from_metadata, and unit tests.
crates/orchestrator/src/jobs/types.rs Added PartialEq to JobType and PartialOrd to JobStatus enums.
crates/orchestrator/src/lib.rs Introduced modules for various services and utilities.
crates/orchestrator/src/main.rs Reorganized imports using orchestrator namespace.
crates/orchestrator/src/queue/mod.rs Added #[automock] to QueueProvider trait.
crates/orchestrator/src/tests/common/constants.rs Introduced MADARA_RPC_URL constant.
crates/orchestrator/src/tests/common/mod.rs Added functions for initializing configurations and job fixtures.
crates/orchestrator/src/tests/database/mod.rs Introduced test_database() function with rstest and tokio.
crates/orchestrator/src/tests/jobs/da_job/mod.rs Added test functions for job operations.
crates/orchestrator/src/tests/jobs/mod.rs Introduced test functions for job creation and verification.
crates/orchestrator/src/tests/mod.rs Added public modules for database, jobs, server, queue, and common.
crates/orchestrator/src/tests/queue/mod.rs Introduced test_queue function with rstest and tokio.
crates/orchestrator/src/tests/server/mod.rs Added test functions for health endpoint and consumer initialization.

🐇
In the land of code, the rabbits hop,
With mockall and httpmock, they never stop.
Configs are public, jobs are tested,
In orchestrator's fields, all bugs are bested.
The queues are mocked, the databases checked,
With every change, the system's decked.
Celebrating code with a fluffy cheer,
The rabbits code on, year after year. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@AryanGodara AryanGodara changed the title Write Unit tests Write Integration tests Apr 15, 2024
crates/orchestrator/src/config.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/config.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/src/jobs/da_job/mod.rs Show resolved Hide resolved
crates/orchestrator/tests/common/constants.rs Outdated Show resolved Hide resolved
crates/orchestrator/tests/config/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/tests/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/tests/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/tests/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
crates/orchestrator/tests/jobs/da_job/mod.rs Outdated Show resolved Hide resolved
@apoorvsadana apoorvsadana marked this pull request as ready for review May 24, 2024 18:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (1)
crates/orchestrator/src/config.rs (1)

30-45: Initialization of the application configuration is robust, using environment variables effectively. Consider using a trait for the DA client as suggested in previous reviews for better modularity.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3fe3733 and 8384cb0.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (20)
  • Cargo.toml (1 hunks)
  • crates/da_clients/da-client-interface/Cargo.toml (1 hunks)
  • crates/da_clients/da-client-interface/src/lib.rs (2 hunks)
  • crates/orchestrator/Cargo.toml (3 hunks)
  • crates/orchestrator/src/config.rs (3 hunks)
  • crates/orchestrator/src/database/mod.rs (2 hunks)
  • crates/orchestrator/src/jobs/da_job/mod.rs (1 hunks)
  • crates/orchestrator/src/jobs/mod.rs (1 hunks)
  • crates/orchestrator/src/jobs/types.rs (2 hunks)
  • crates/orchestrator/src/lib.rs (1 hunks)
  • crates/orchestrator/src/main.rs (1 hunks)
  • crates/orchestrator/src/queue/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/common/constants.rs (1 hunks)
  • crates/orchestrator/src/tests/common/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/database/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/jobs/da_job/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/jobs/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/queue/mod.rs (1 hunks)
  • crates/orchestrator/src/tests/server/mod.rs (1 hunks)
Files skipped from review due to trivial changes (7)
  • Cargo.toml
  • crates/da_clients/da-client-interface/Cargo.toml
  • crates/orchestrator/src/main.rs
  • crates/orchestrator/src/tests/common/constants.rs
  • crates/orchestrator/src/tests/database/mod.rs
  • crates/orchestrator/src/tests/mod.rs
  • crates/orchestrator/src/tests/queue/mod.rs
Additional comments not posted (15)
crates/orchestrator/src/lib.rs (1)

1-19: Module declarations are well-organized and correctly scoped.

crates/orchestrator/src/queue/mod.rs (1)

8-14: Introduction of automock for QueueProvider is a good practice for enabling easier testing.

crates/da_clients/da-client-interface/src/lib.rs (1)

Line range hint 4-17: Proper use of automock on DaClient trait enhances testability by allowing the creation of mock objects.

crates/orchestrator/Cargo.toml (1)

23-29: Dependencies are correctly added and versioned. The addition of mockall and starknet-core is crucial for mocking and blockchain interactions respectively.

Also applies to: 43-46

crates/orchestrator/src/database/mod.rs (1)

Line range hint 4-20: Introduction of automock for the Database trait is beneficial for testing, allowing the creation of mock objects.

crates/orchestrator/src/tests/server/mod.rs (3)

13-32: Setup function for the server looks robust and well-handled.


34-51: Health endpoint test is comprehensive and correctly asserts both the status code and response body.


53-57: Consumer initialization test is concise and effectively checks the operation's success.
[APROVED]

crates/orchestrator/src/tests/common/mod.rs (2)

25-47: The init_config function is well-designed, providing flexible test setup with optional mock components.


49-68: Job item fixtures are well-implemented, ensuring flexibility and uniqueness for test cases.

crates/orchestrator/src/tests/jobs/da_job/mod.rs (3)

25-40: The test_create_job function correctly tests the creation of a DA job, ensuring all properties are set as expected.


42-50: The test_verify_job function effectively tests the job verification process using a mock DA client, ensuring the function behaves as expected under simulated conditions.


52-103: The test_process_job function is comprehensive, using a mock server and DA client to thoroughly test the job processing logic.

crates/orchestrator/src/jobs/types.rs (1)

Line range hint 69-81: The enhancements to the JobType and JobStatus enums, adding PartialEq and PartialOrd, improve their usability in logical comparisons and sorting operations.

crates/orchestrator/src/jobs/da_job/mod.rs (1)

Line range hint 1-214: The DaJob implementation is robust, with well-structured methods for creating, processing, and verifying jobs. The use of async patterns and structured error handling enhances the maintainability and reliability of the code.

Comment on lines +183 to +188
let attempt = get_u64_from_metadata(metadata, key)?;
let incremented_value = attempt.checked_add(1);
if incremented_value.is_none() {
return Err(eyre!("Incrementing key {} in metadata would exceed u64::MAX", key));
}
new_metadata.insert(key.to_string(), incremented_value.unwrap().to_string());
Copy link

Choose a reason for hiding this comment

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

Consider handling non-existent keys more idiomatically by using entry API.

fn increment_key_in_metadata(metadata: &HashMap<String, String>, key: &str) -> Result<HashMap<String, String>> {
    let mut new_metadata = metadata.clone();
    let attempt = get_u64_from_metadata(metadata, key)?;
    let incremented_value = attempt.checked_add(1).ok_or_else(|| eyre!("Incrementing key {} in metadata would exceed u64::MAX", key))?;
    new_metadata.entry(key.to_string()).or_insert_with(|| "0".to_string()).replace(incremented_value.to_string());
    Ok(new_metadata)
}

if incremented_value.is_none() {
return Err(eyre!("Incrementing key {} in metadata would exceed u64::MAX", key));
}
new_metadata.insert(key.to_string(), incremented_value.unwrap().to_string());
Copy link

Choose a reason for hiding this comment

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

Improve error handling when parsing string to u64.

fn get_u64_from_metadata(metadata: &HashMap<String, String>, key: &str) -> Result<u64> {
    metadata.get(key).unwrap_or(&"0".to_string()).parse::<u64>().map_err(|e| eyre!("Failed to parse metadata value for key {}: {}", key, e))
}

#[rstest]
#[tokio::test]
async fn create_job_fails_job_already_exists() {
// TODO
Copy link

Choose a reason for hiding this comment

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

Incomplete test implementation.

Would you like me to help complete this test function or should we track this as a task in your project management tool?

#[rstest]
#[tokio::test]
async fn create_job_fails_works_new_job() {
// TODO
Copy link

Choose a reason for hiding this comment

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

Incomplete test implementation.

Would you like me to help complete this test function or should we track this as a task in your project management tool?

@apoorvsadana apoorvsadana merged commit b8a9748 into madara-alliance:main May 24, 2024
6 checks passed
ocdbytes pushed a commit that referenced this pull request Oct 16, 2024
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.

2 participants