selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[grid][java]: apply protocol version in relay session factory

Open VietND96 opened this issue 1 year ago • 5 comments

User description

Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

A missing in part of last PR #13849 for a workaround in the relay node with Appium

To ensure the fix works, I set up an end2end test where able to execute and verify the session can be created successfully based on the dev package built locally. Result as below

image

Tested TOML

[server]
port = 5556

[node]
detect-drivers = false

[relay]
url = "http://localhost:4723"
status-endpoint = "/status"
protocol-version = "HTTP/1.1"
configs = [
    '1', '{"platformName": "android", "appium:platformVersion": "14", "appium:deviceName": "emulator-5554", "appium:automationName": "uiautomator2", "appium:browserName": "chrome", "browserName": "chrome"}'
]

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x] I have read the contributing document.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

Type

Bug fix


Description

  • The PR addresses an issue where the serviceProtocolVersion was not being applied to the clientConfig in RelaySessionFactory.
  • This change ensures that if serviceProtocolVersion is provided, it is set in the clientConfig which is used to create a new session.

Changes walkthrough

Relevant files
Enhancement
RelaySessionFactory.java
Apply Protocol Version in RelaySessionFactory                       

java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java

  • Added conditional application of serviceProtocolVersion to
    clientConfig if it is not empty.
  • +3/-0     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    VietND96 avatar Apr 26 '24 07:04 VietND96

    PR Description updated to latest commit (https://github.com/SeleniumHQ/selenium/commit/eed2f818b3557c5f3250a8092e2bb39f9c0dec4e)

    qodo-code-review[bot] avatar Apr 26 '24 07:04 qodo-code-review[bot]

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized and straightforward, involving only a conditional addition of a protocol version to the client configuration. The logic is simple and the impact is limited to a specific part of the code.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The check for serviceProtocolVersion.isEmpty() assumes that serviceProtocolVersion is not null. If serviceProtocolVersion can be null, this could lead to a NullPointerException. It would be safer to include a null check.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview: The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    qodo-code-review[bot] avatar Apr 26 '24 07:04 qodo-code-review[bot]

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Use a local variable for the modified client configuration to ensure thread safety.

    To ensure thread safety and immutability, consider using a local variable for the modified
    clientConfig when setting the version, instead of reassigning the existing clientConfig
    variable. This approach avoids potential issues in a multi-threaded environment where
    clientConfig might be shared or reused.

    java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java [162-164]

    +ClientConfig updatedClientConfig = clientConfig;
     if (!serviceProtocolVersion.isEmpty()) {
    -  clientConfig = clientConfig.version(serviceProtocolVersion);
    +  updatedClientConfig = clientConfig.version(serviceProtocolVersion);
     }
    +HttpClient client = clientFactory.createClient(updatedClientConfig);
     
    

    ✨ Improve tool usage guide:

    Overview: The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    qodo-code-review[bot] avatar Apr 26 '24 07:04 qodo-code-review[bot]

    I cannot update the fork because maintainers have no permission, this is missing

    image

    diemol avatar May 03 '24 22:05 diemol

    @diemol probably the fork in an org and something restricted that I can't remove. Anyhow, I just rebased the branch

    VietND96 avatar May 04 '24 04:05 VietND96