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

Pass sleep_time as argument in wait_for_condition method #2270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

geetikakay
Copy link
Contributor

@geetikakay geetikakay commented Jan 9, 2025

Short description:

Add sleep_time as argument. Resources like pipeline,pipeline runs need more time and polling in '1s' is not needed.

More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:

Summary by CodeRabbit

  • New Features
    • Enhanced wait_for_condition method with configurable sleep interval between retry attempts
    • Added optional sleep_time parameter to control wait duration during resource condition checks

Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces a modification to the wait_for_condition method in the Resource class within the ocp_resources/resource.py file. The change adds a new optional parameter sleep_time with a default value of 1 second, allowing more flexible control over the interval between condition checks. This enhancement provides users with the ability to customize the waiting period during resource condition monitoring.

Changes

File Change Summary
ocp_resources/resource.py - Updated wait_for_condition method signature to include sleep_time parameter
- Modified TimeoutSampler calls to use the new sleep_time parameter
- Updated method's docstring to explain the new parameter

Finishing Touches

  • 📝 Generate Docstrings

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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: 0

🔭 Outside diff range comments (1)
ocp_resources/resource.py (1)

Test coverage needed for the sleep_time parameter

The wait_for_condition method is tested in tests/test_resources.py, but there are no explicit test cases verifying the behavior with different sleep_time values. Consider adding test cases to verify:

  • Custom sleep intervals work as expected
  • Edge cases (e.g., very small or large sleep times)
🔗 Analysis chain

Line range hint 1030-1062: Verify the usage of the new parameter in tests.

The implementation looks correct, but we should verify that tests are updated to cover the new parameter.

Run the following script to check for test coverage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for wait_for_condition method
# Look for test files that use wait_for_condition
rg -l "wait_for_condition" test_*.py

# Look for specific test cases that verify the sleep_time parameter
rg "wait_for_condition.*sleep_time" test_*.py

Length of output: 188


Script:

#!/bin/bash
# First, find all test files in the repository
echo "=== Finding test files ==="
fd "test_.+\.py$"

# Then search for wait_for_condition usage in the entire repo
echo -e "\n=== Searching for wait_for_condition usage ==="
rg -A 2 "wait_for_condition" 

# Look for specific test cases with sleep_time parameter
echo -e "\n=== Searching for sleep_time parameter usage ==="
rg "wait_for_condition.*sleep_time"

Length of output: 1981

🧹 Nitpick comments (1)
ocp_resources/resource.py (1)

Line range hint 1030-1062: Consider renaming parameter and adding validation.

The implementation looks good and achieves the PR objective. However, consider these improvements:

  1. Rename sleep_time to polling_interval to better indicate its purpose
  2. Add validation for non-positive values that could cause issues

Apply this diff to improve the implementation:

-def wait_for_condition(self, condition: str, status: str, timeout: int = 300, sleep_time: int = 1) -> None:
+def wait_for_condition(self, condition: str, status: str, timeout: int = 300, polling_interval: int = 1) -> None:
     """
     Wait for Resource condition to be in desire status.
 
     Args:
         condition (str): Condition to query.
         status (str): Expected condition status.
         timeout (int): Time to wait for the resource.
-        sleep_time(int): Interval between each retry when checking the resource's condition.
+        polling_interval (int): Interval in seconds between condition checks.
 
     Raises:
         TimeoutExpiredError: If Resource condition in not in desire status.
+        ValueError: If polling_interval is less than or equal to 0.
     """
+    if polling_interval <= 0:
+        raise ValueError("polling_interval must be greater than 0")
+
     self.logger.info(f"Wait for {self.kind}/{self.name}'s '{condition}' condition to be '{status}'")
 
     timeout_watcher = TimeoutWatch(timeout=timeout)
     for sample in TimeoutSampler(
         wait_timeout=timeout,
-        sleep=sleep_time,
+        sleep=polling_interval,
         func=lambda: self.exists,
     ):
         if sample:
             break
 
     for sample in TimeoutSampler(
         wait_timeout=timeout_watcher.remaining_time(),
-        sleep=sleep_time,
+        sleep=polling_interval,
         func=lambda: self.instance,
     ):
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e16b6a and b9adba2.

📒 Files selected for processing (1)
  • ocp_resources/resource.py (2 hunks)

@geetikakay
Copy link
Contributor Author

/verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants