-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: introduced retry rules for flaky android push tests #1036
Conversation
WalkthroughA new class named Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant RetryTestRule
participant Test
TestRunner->>RetryTestRule: Initialize with retry count (2)
RetryTestRule->>Test: Execute test
alt Test fails
RetryTestRule->>Test: Retry test (1st attempt)
alt Test fails
RetryTestRule->>Test: Retry test (2nd attempt)
alt Test fails
RetryTestRule->>TestRunner: Throw last exception
else Test passes
RetryTestRule->>TestRunner: Return success
end
else Test passes
RetryTestRule->>TestRunner: Return success
end
else Test passes
RetryTestRule->>TestRunner: Return success
end
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
9661a9c
to
0718012
Compare
3aa8e11
to
f8a5578
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Inline review comments failed to post
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (4)
android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (4)
91-93
: LGTM! Consider making retry count configurable.The addition of the RetryTestRule is a good practice for handling flaky tests. The current implementation with a retry count of 2 is reasonable. However, you might want to consider making this retry count configurable, perhaps through a constant or a configuration parameter. This would allow easier adjustments for different test environments or specific test cases that might require more or fewer retries.
Consider refactoring the retry rule initialization to use a configurable retry count:
- public RetryTestRule retryRule = new RetryTestRule(2); + private static final int RETRY_COUNT = 2; + public RetryTestRule retryRule = new RetryTestRule(RETRY_COUNT);This change would make it easier to adjust the retry count in the future if needed.
Line range hint
4-5
: Consider addressing disabled testsThere are commented out or disabled test cases in this file. It's generally a good practice to either fix and enable these tests or remove them if they are no longer relevant. Keeping disabled tests in the codebase can lead to confusion and maintenance overhead.
Please review all disabled tests in this file and either:
- Fix and enable them
- Remove them if they are no longer needed
- Add a comment explaining why they are disabled and create an issue to track their resolution
This will help maintain a clean and up-to-date test suite.
Line range hint
4-5
: Resolve TODO commentsThere are TODO comments in the code. While TODOs can be useful for temporary notes, they should be resolved or converted into trackable issues to ensure they're not forgotten.
Please review all TODO comments in this file and either:
- Implement the required functionality
- Remove the TODO if it's no longer relevant
- Convert the TODO into a GitHub issue for proper tracking
This will help ensure that all necessary improvements are properly tracked and implemented.
Line range hint
1-1036
: Consider splitting the test fileThis test file is quite large and contains numerous test cases for different scenarios. While it's comprehensive, it might be beneficial to split it into smaller, more focused test classes. This could improve readability, maintainability, and potentially test execution time if parallel test execution is possible.
Consider refactoring this large test file into smaller, more focused test classes. For example:
AndroidPushActivationTest
AndroidPushDeactivationTest
AndroidPushSubscriptionTest
AndroidPushErrorHandlingTest
This refactoring would make the test suite more modular and easier to maintain. It would also make it easier to run specific groups of tests when needed.
🛑 Comments failed to post (2)
android/src/androidTest/java/io/ably/lib/test/RetryTestRule.java (2)
36-36:
⚠️ Potential issueFix string formatting in error messages
The error messages in
System.err.println
at lines 36 and 42 use placeholders like${description.methodName}
and$runCount
, which won't be interpolated in Java strings. To include variables in the output, use string concatenation orString.format()
. Also,$runCount
is not defined; you can use(i + 1)
to indicate the current run count.Apply this diff to fix the error messages:
- System.err.println("${description.methodName}: test failed on run: `$runCount`. Will run a maximum of `$timesToRunTestCount` times."); + System.err.println(description.getMethodName() + ": test failed on run: " + (i + 1) + ". Will run a maximum of " + timesToRunTestCount + " times.");- System.err.println("${description.displayName}: giving up after `$timesToRunTestCount` failures"); + System.err.println(description.getDisplayName() + ": giving up after " + timesToRunTestCount + " failures");Also applies to: 42-42
14-17:
⚠️ Potential issueValidate
times
parameter in constructorCurrently, the constructor does not validate the
times
parameter. If a negative value is passed, it could lead to unexpected behavior. Consider adding a check to ensuretimes
is non-negative.Apply this diff to add validation:
public RetryTestRule(int times) { + if (times < 0) { + throw new IllegalArgumentException("times must be non-negative"); + } this.timesToRunTestCount = times + 1; }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.public RetryTestRule(int times) { if (times < 0) { throw new IllegalArgumentException("times must be non-negative"); } this.timesToRunTestCount = times + 1; }
f8a5578
to
2a85870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think JUNIT5 supports intelligent retry for failing tests.
junit-team/junit5#3142.
Maybe it's time we should update to JUNIT5
Not sure if Junit5 really added native support for retries, but surely some hacks available out there junit-team/junit5#1558 (comment) |
@sacOO7 yes, junit 5 indeed has retry support out of the box, but unfortunately Android runner doesn't support junit 5. Here is issue for this https://issuetracker.google.com/issues/127100532 |
Sure, let's just make sure existing retry script is stable enough to handle proper retries. Also, there are lot of retry scripts available online -> junit-team/junit5#1558 (comment) |
f75ca55
to
1d04fc4
Compare
e20c9a5
to
3d017ab
Compare
3d017ab
to
4b13635
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
.github/workflows/emulate.yml (2)
38-38
: Approved: Enhanced logging for better debugging.Adding the
--info
flag to the Gradle command is a good improvement. It will provide more detailed output during the test execution, which can be crucial for debugging issues in the CI environment, especially for flaky tests.Consider using the
--info
flag conditionally. You could set up a GitHub Actions input variable to control the verbosity level, allowing for more flexibility:inputs: gradle-log-level: description: 'Gradle log level (quiet, lifecycle, info, debug)' required: false default: 'lifecycle' steps: - uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ matrix.android-api-level }} script: ./gradlew :android:connectedAndroidTest --${{ inputs.gradle-log-level }}This way, you can easily adjust the log level without modifying the workflow file, which can be useful for debugging specific runs without permanently increasing log verbosity.
Line range hint
1-45
: Overall improvement in debugging capabilities.The addition of the
--info
flag to the Gradle command aligns well with the PR objectives of addressing flaky Android push tests. This change enhances the workflow's ability to provide detailed information during test execution, which is crucial for identifying and resolving intermittent failures.To further improve the handling of flaky tests, consider implementing a mechanism to track and report on test flakiness over time. This could involve:
- Parsing the Gradle output to identify flaky tests.
- Storing the results of flaky tests in a separate artifact or database.
- Creating a custom GitHub Action or script to analyze and report on test flakiness trends.
This approach would provide valuable insights into which tests are consistently problematic and help prioritize test stability efforts.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- .github/workflows/emulate.yml (1 hunks)
- android/build.gradle.kts (1 hunks)
- android/src/androidTest/java/io/ably/lib/test/RetryTestRule.java (1 hunks)
- android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- android/src/androidTest/java/io/ably/lib/test/RetryTestRule.java
- android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java
🔇 Additional comments (1)
android/build.gradle.kts (1)
Line range hint
34-36
: Reconsider disabling lint errorsSetting
abortOnError = false
in the lint configuration prevents the build from failing due to lint errors. While this can be useful in certain CI/CD scenarios, it might hide important issues that should be addressed.Consider the following alternatives:
Instead of disabling all lint errors, you could selectively ignore specific lint issues that are known to be false positives or not applicable to your project. This can be done using the
disable
orignore
options in the lint configuration.If this change is intended to address specific CI/CD pipeline issues, it might be better to configure the CI tool to continue despite lint errors, rather than modifying the project's build configuration.
If you decide to keep this configuration, ensure that lint errors are still being reported and reviewed regularly, perhaps as part of your code review process.
To help make an informed decision, let's check if there are any current lint issues in the project:
This script will help determine if there are current lint issues that need addressing, which can guide the decision on whether to keep
abortOnError = false
.✅ Verification successful
Lint Configuration Verification
No lint issues currently found in the project. Disabling lint errors with
abortOnError = false
is not hiding any existing issues.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for lint issues in the project # Run lint and capture the output ./gradlew lint > lint_output.txt 2>&1 # Check if there are any errors or warnings if grep -E "Error:|Warning:" lint_output.txt; then echo "Lint issues found. Consider addressing these before disabling lint errors." else echo "No lint issues found. Disabling lint errors might not be necessary." fi # Clean up rm lint_output.txtLength of output: 226
4b13635
to
668f41d
Compare
668f41d
to
785cd2a
Compare
785cd2a
to
79114e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (4 hunks)
- android/src/main/AndroidManifest.xml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java
11cbdca
to
eaa7f67
Compare
eaa7f67
to
43a7dbc
Compare
43a7dbc
to
d7afbfe
Compare
d7afbfe
to
90a743c
Compare
90a743c
to
88a18f8
Compare
88a18f8
to
c450b20
Compare
c450b20
to
bb21435
Compare
There was a problem hiding this 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 and nitpick comments (2)
android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (2)
91-93
: LGTM! Consider extracting the retry count to a constant.The addition of the
RetryTestRule
is a good approach to handle flaky tests, which is particularly useful for push notification testing. This aligns well with the PR objective of enhancing test reliability.Consider extracting the retry count (2) to a private static final constant at the class level. This would make it easier to adjust the retry count in the future if needed. For example:
private static final int RETRY_COUNT = 2; @Rule public RetryTestRule retryRule = new RetryTestRule(RETRY_COUNT);
Line range hint
1-1843
: Consider cleanup and potential refactoring of the test suite.While reviewing the file, I noticed a few areas that could be improved:
There are some TODO comments in the code (e.g., line 4). It would be good to address these or create issues to track them if they can't be resolved immediately.
There's a commented-out test method
Realtime_push_interface
(around line 1443). If this test is no longer needed, consider removing it. If it's still relevant, please uncomment and update it as necessary.Given the size and complexity of this test suite, it might be beneficial to consider splitting it into smaller, more focused test classes. This could improve readability and maintainability.
Could you please review these suggestions and let me know your thoughts on potentially refactoring the test suite?
#!/bin/bash # Find TODO comments and commented-out methods echo "TODO comments:" rg "TODO" AndroidPushTest.java echo "Commented-out methods:" rg "//\s*@Test" AndroidPushTest.java
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- .github/workflows/emulate.yml (1 hunks)
- android/build.gradle.kts (2 hunks)
- android/src/androidTest/java/io/ably/lib/test/RetryTestRule.java (1 hunks)
- android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (6 hunks)
- gradle/libs.versions.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- .github/workflows/emulate.yml
- android/build.gradle.kts
- android/src/androidTest/java/io/ably/lib/test/RetryTestRule.java
- gradle/libs.versions.toml
🔇 Additional comments (2)
android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.java (2)
Line range hint
1-1843
: Summary of AndroidPushTest.java reviewOverall, the changes to this file are positive and align with the PR objective of enhancing the reliability of Android push tests. The addition of the
RetryTestRule
should help manage flaky tests, and the@SdkSuppress
annotation ensures that certain tests run on appropriate Android versions.However, there are a few points that could use attention:
- Consider extracting the retry count to a constant for easier maintenance.
- Clarification is needed on the reason for the SDK version restriction in the
WaitingForNewPushDeviceDetails_on_GotPushDeviceDetails
test.- Some cleanup of TODO comments and commented-out code would be beneficial.
- Given the size and complexity of this test suite, consider refactoring it into smaller, more focused test classes in the future.
Please review these suggestions and let me know if you need any further clarification or have any questions.
983-983
: LGTM! Please clarify the reason for SDK version restriction.The addition of
@SdkSuppress(minSdkVersion = 21)
to theWaitingForNewPushDeviceDetails_on_GotPushDeviceDetails
test is approved. This ensures the test runs only on Android 5.0 (Lollipop) and above.Could you please clarify the specific reason for restricting this test to Android 5.0 and above? Is there a particular push notification feature or behavior that's only available or reliable from this version onwards?
Also, if the library still supports Android versions below 5.0, how is the functionality tested for those versions?
✅ Verification successful
Verified! The
@SdkSuppress(minSdkVersion = 21)
annotation is correctly applied toWaitingForNewPushDeviceDetails_on_GotPushDeviceDetails
, and there are no other tests for this functionality without SDK restrictions.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if there are any other tests for the same functionality without SDK restrictions rg --type java "WaitingForNewPushDeviceDetails.*GotPushDeviceDetails" -g '!AndroidPushTest.java'Length of output: 98
Script:
#!/bin/bash # Search for the specific test method across the entire codebase rg --type java "WaitingForNewPushDeviceDetails_on_GotPushDeviceDetails" # Search within AndroidPushTest.java for any conditional SDK version checks rg --type java "@SdkSuppress" android/src/androidTest/java/io/ably/lib/test/android/AndroidPushTest.javaLength of output: 417
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM since tests are passing
Added retry rules to prevent flaky android push test fail CI
Summary by CodeRabbit
RetryTestRule
to enhance test reliability by allowing tests to be retried upon failure.AndroidPushTest
class, permitting tests to retry up to two times if they fail.android-test
dependency to improve testing capabilities.These improvements aim to ensure more consistent test outcomes and reduce false negatives during testing.