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

Refactor scenario validation logic to improve clarity and adjust time… #584

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

kooomix
Copy link
Contributor

@kooomix kooomix commented Jan 16, 2025

User description

…out settings for scan status checks


PR Type

Bug fix, Enhancement


Description

  • Refactored verify_scan_status method for improved clarity.

  • Adjusted timeout settings for scan status checks.

  • Reordered and updated validation logic for scan status.

  • Added missing sleep interval for consistency in processing.


Changes walkthrough 📝

Relevant files
Enhancement
scenarios_manager.py
Refactored and optimized scan status validation logic       

systest_utils/scenarios_manager.py

  • Refactored verify_scan_status method for better readability.
  • Adjusted timeout values for scan status checks.
  • Moved and updated validation for lastPostureScanTriggered.
  • Added sleep_interval to attack chains processing validation.
  • +10/-10 

    Need help?
  • Type /help how to ... in the comments thread for any question about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Timeout Reduction

    The timeout for lastPostureScanTriggered validation was reduced from 30 to 1 second, which may be too aggressive and cause flaky test behavior

    timeout=1,
    Validation Order

    Moving the lastPostureScanTriggered validation to the end of the method may hide timing issues since it now happens after all other validations complete

    Logger.logger.info("validating lastPostureScanTriggered for this cluster was updated")
    r, t = self.wait_for_report(
        self.verify_cluster_lastPostureScanTriggered_time,
        timeout=1,
        cluster_name=self.cluster,
        trigger_time=trigger_time
        )

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Increase timeout duration to prevent false negatives due to insufficient wait time

    The timeout value of 1 second for validating lastPostureScanTriggered is too short
    and could lead to false negatives. Consider increasing it to a more reasonable value
    (e.g., 30 seconds) to account for potential network latency and processing delays.

    systest_utils/scenarios_manager.py [729-734]

     r, t = self.wait_for_report(
         self.verify_cluster_lastPostureScanTriggered_time,
    -    timeout=1,
    +    timeout=30,
         cluster_name=self.cluster,
         trigger_time=trigger_time
     )
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The 1 second timeout is extremely short and likely to cause flaky test failures. The original code used 30 seconds which is much more reasonable for this type of validation.

    9
    General
    Add sleep interval to prevent excessive polling in wait operation

    The security risks validation is missing a sleep_interval parameter, which could
    lead to excessive CPU usage due to tight polling. Add a sleep_interval consistent
    with other similar operations.

    systest_utils/scenarios_manager.py [720-726]

     r, t = self.wait_for_report(
         self.verify_cluster_field_in_scan_status, 
         timeout=180,
    +    sleep_interval=5,
         cluster_name=self.cluster,
         expected_field='securityRisksProcessingStatus',
         expectedStatus='done'
     )
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding sleep_interval=5 is consistent with other similar wait operations in the code and prevents excessive CPU usage from tight polling loops.

    7

    Copy link

    Failed to generate code suggestions for PR

    @kooomix kooomix merged commit 9fb5f04 into master Jan 16, 2025
    2 checks passed
    @kooomix kooomix deleted the fix_scan_state branch February 3, 2025 12:25
    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.

    1 participant