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

[ECO-5190] Fallbacks in custom environment #2017

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Jan 23, 2025

Closes #2009

Summary by CodeRabbit

Release Notes

  • New Features

    • Added new factory methods for creating ARTRealtime instances with different parameters
    • Enhanced host fallback mechanism for more flexible connection handling
  • Bug Fixes

    • Improved handling of empty environment strings in fallback host generation
  • Tests

    • Updated test suite to improve connection and host fallback testing
    • Added environment-specific test scenarios
    • Skipped certain network-related test cases for further review

…s nil by default (and for production) and translates to an empty string in swift. Since `fallbackHostsWithEnvironment:` accepts nil, so `ARTClientOptions.environment` should be nullable (TO3k1). But this is breaking change, thus using workaround. I haven't created an issue, since https://sdk.ably.com/builds/ably/specification/main/features/#TO3k1 is marked as deprecated.
…k hosts. The old check didn't take into account that there might be an environment prefix.
…t. I'm not sure why all errors with `kCFErrorDomainCFNetwork` domain should be considered as "no internet", since library itself treats it as "host unreachable" in `ARTWebSocketTransport.classifyError`. Thus skipping the test.
Copy link

coderabbitai bot commented Jan 23, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 SwiftLint (0.57.0)
Test/Tests/RealtimeClientConnectionTests.swift

[
{
"character" : 42,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 107,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 44,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 109,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 86,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 125,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 60,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 127,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 46,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 139,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 183,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 857,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 898,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 930,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 971,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1029,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1241,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1280,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1671,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1716,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1768,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 1933,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 119,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2011,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 52,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2177,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2582,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2604,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2615,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2644,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2658,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2684,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2698,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 53,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2731,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2751,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 54,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2905,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2953,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3175,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 66,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3320,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 58,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3669,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 58,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3700,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 24,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3729,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 66,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3769,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 66,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3780,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 66,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3811,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 44,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4430,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 61,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4465,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 61,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4477,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 53,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4487,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4500,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4534,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4581,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4598,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 59,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4645,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4698,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 45,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5261,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 45,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5341,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 45,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5385,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 60,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5390,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 39,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 102,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 11,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 103,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 27,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3381,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 27,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3441,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 31,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3532,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 36,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5275,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 57,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5310,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 36,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5361,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 57,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 5417,
"reason" : "Force tries should be avoided",
"rule_id" : "force_try",
"severity" : "Error",
"type" : "Force Try"
},
{
"character" : 73,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 2292,
"reason" : "Initializing an optional variable with nil is redundant",
"rule_id" : "redundant_optional_initialization",
"severity" : "Warning",
"type" : "Redundant Optional Initialization"
},
{
"character" : 55,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3087,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3346,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3414,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3466,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 48,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3470,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 47,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3474,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3489,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3493,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3508,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 47,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3512,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3554,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3604,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 58,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3678,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 57,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3709,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 60,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3735,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 64,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 3738,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4579,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4643,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 50,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4878,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientConnectionTests.swift",
"line" : 4907,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
}
]

Walkthrough

The pull request introduces modifications to the Ably Realtime client's host fallback mechanism. In the ARTDefault.m file, a new conditional check handles empty environment strings by converting them to nil. In ARTRealtime.m, three new class methods are added to create instances with different parameters, and the fallback host selection logic is refined. The RealtimeClientConnectionTests.swift file is updated with new test methods to validate the fallback behavior across different environments, including production and sandbox scenarios.

Changes

File Changes
Source/ARTDefault.m Added conditional check to handle empty environment strings in fallbackHostsWithEnvironment: method
Source/ARTRealtime.m - Added three class methods: createWithOptions:, createWithKey:, createWithToken:
- Modified realtimeTransportFailed:withError: to use suffix-based host matching
Test/Tests/RealtimeClientConnectionTests.swift - Renamed and modified existing test methods
- Added new test methods for production and sandbox environments
- Skipped certain test methods

Assessment against linked issues

Objective Addressed Explanation
Use fallback hosts in custom environments [#2009, ECO-5190]

Possibly related PRs

Suggested reviewers

  • umair-ably

Poem

🐰 Hosts dancing in the code's embrace,
Fallback paths with algorithmic grace,
Empty strings now turn to nil,
Realtime connections climb the hill,
A rabbit's leap of logic's might! 🌟


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.

CodeRabbit Configuration 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.

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

🧹 Nitpick comments (3)
Test/Tests/RealtimeClientConnectionTests.swift (2)

Line range hint 3841-3892: Consider removing or updating the deprecated test function.

The function test__086__Connection__Host_Fallback__failing_connections_with_custom_endpoint_should_result_in_an_error_immediately() is marked as deprecated. To maintain a clean codebase, consider updating the test to avoid using deprecated properties or removing it if it's no longer necessary.


Line range hint 4045-4055: Review the decision to skip this test function.

The test function skipped_test__102__Connection__Host_Fallback__should_move_to_disconnected_when_there_s_no_internet__with_any_kCFErrorDomainCFNetwork() has been prefixed with skipped_, effectively skipping it. Please review whether this test is still needed. If it is obsolete, consider removing it entirely. If it requires fixes, address them to re-enable the test.

Source/ARTRealtime.m (1)

1640-1640: Consider using a more robust host comparison method.

The current implementation uses string suffix comparison to identify the default realtime host. This could be fragile if the host string contains multiple occurrences of the default host pattern.

Consider using a more robust comparison method, such as:

-if (!_fallbacks && [transportError.url.host hasSuffix:[ARTDefault realtimeHost]]) {
+if (!_fallbacks && [self isDefaultRealtimeHost:transportError.url.host]) {

And add a helper method:

- (BOOL)isDefaultRealtimeHost:(NSString *)host {
    NSString *defaultHost = [ARTDefault realtimeHost];
    return [host hasSuffix:defaultHost] && 
           (host.length == defaultHost.length || 
            [host characterAtIndex:host.length - defaultHost.length - 1] == '.');
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35805d0 and 18c34f5.

📒 Files selected for processing (3)
  • Source/ARTDefault.m (1 hunks)
  • Source/ARTRealtime.m (1 hunks)
  • Test/Tests/RealtimeClientConnectionTests.swift (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: check
  • GitHub Check: build
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: check
🔇 Additional comments (7)
Test/Tests/RealtimeClientConnectionTests.swift (5)

4144-4146: LGTM!

The assertions correctly verify the order of URL connections in the host fallback mechanism.


4149-4152: LGTM!

The new test function for the production environment appropriately extends the test coverage.


4241-4244: LGTM!

The addition of the test function for the production environment correctly tests the retry logic in host fallback.


4441-4441: LGTM!

The regular expression in the assertion accurately matches the expected URL pattern for fallback hosts, including optional 'sandbox-' and '-fallback' prefixes.


4093-4097: ⚠️ Potential issue

Fix the optional binding syntax in if let env statement.

In line 4095, the if let statement is missing the assignment to unwrap the optional env. The correct syntax is if let env = env {. Please update the code to fix this syntax error.

Apply this diff to fix the syntax error:

- if let env {
+ if let env = env {

Likely invalid or redundant comment.

Source/ARTDefault.m (1)

28-30: LGTM!

The added conditional check correctly handles empty environment strings by setting them to nil. This ensures that fallback hosts are generated properly without unintended prefixes.

Source/ARTRealtime.m (1)

Line range hint 1-1800: LGTM! The implementation is robust and well-structured.

The code demonstrates good practices in terms of:

  • Comprehensive error handling
  • Proper connection state management
  • Detailed logging for debugging
  • Clean memory management

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

Successfully merging this pull request may close these issues.

Realtime connection does not use fallback hosts in custom environment
1 participant