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-4327] Feature - realtime fallbacks #657

Merged
merged 30 commits into from
Aug 27, 2024
Merged

Conversation

sacOO7
Copy link
Collaborator

@sacOO7 sacOO7 commented Aug 5, 2024

Fixed #225

Summary by CodeRabbit

  • Documentation

    • Updated the README to remove outdated statements regarding realtime connection handling and feature implementations, clarifying current limitations and statuses.
  • New Features

    • Introduced a method to check for active internet connections, improving error handling and connection management.
    • Modified the realtime URL method to accept a specific host, enhancing flexibility.
    • Added capabilities for managing fallback hosts in real-time connections, enhancing robustness during network failures.
    • Implemented a new utility for better error diagnostics in websocket connections.
    • Introduced a new function to facilitate the creation of a RoundTripRecorder instance with a customized HTTP client.
  • Bug Fixes

    • Improved the error handling mechanism in websocket connections, providing richer error information for better diagnostics.
  • Tests

    • Added new tests for validating connection fallback behavior and internet connectivity checking, ensuring enhanced reliability in various scenarios.
  • Chores

    • Refactored test functions for clarity and maintainability, simplifying the test structure.

@sacOO7 sacOO7 changed the title Feature/realtime fallbacks Featurer realtime fallbacks Aug 5, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 5, 2024 12:35 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 5, 2024 12:35 Inactive
@sacOO7 sacOO7 changed the title Featurer realtime fallbacks Feature realtime fallbacks Aug 6, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 6, 2024 12:14 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 6, 2024 12:14 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 7, 2024 14:18 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 7, 2024 14:18 Inactive
@sacOO7 sacOO7 changed the title Feature realtime fallbacks [ECO-4327] Feature - realtime fallbacks Aug 7, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 12, 2024 11:01 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 12, 2024 11:01 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 12, 2024 12:22 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 12, 2024 12:22 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 12, 2024 13:32 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 12, 2024 13:32 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 12, 2024 14:02 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 12, 2024 14:02 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 22, 2024 08:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 22, 2024 08:24 Inactive
@sacOO7 sacOO7 requested a review from amnonbc August 22, 2024 08:25
Copy link
Contributor

@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: 5

Outside diff range, codebase verification and nitpick comments (2)
ably/realtime_client_integration_test.go (1)

138-140: Consider adding a description for the test.

Adding a description or comment at the beginning of the test function can help clarify its purpose and what it is testing.

+// TestRealtime_RTN17_HostFallback tests the host fallback behavior as per RTN17 specification.
func TestRealtime_RTN17_HostFallback(t *testing.T) {
ably/options.go (1)

489-492: Clarify error handling in realtimeURL.

The error handling logic for setting the port in realtimeURL can be clarified with comments.

// Set port if not set in provided realtimeHost
if err != nil {
	port, _ := opts.activePort()
	baseUrl = net.JoinHostPort(baseUrl, strconv.Itoa(port))
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 918eade and 049151c.

Files selected for processing (3)
  • ably/options.go (4 hunks)
  • ably/realtime_client_integration_test.go (3 hunks)
  • ably/realtime_conn.go (4 hunks)

ably/realtime_client_integration_test.go Outdated Show resolved Hide resolved
ably/realtime_client_integration_test.go Outdated Show resolved Hide resolved
ably/realtime_conn.go Show resolved Hide resolved
ably/realtime_conn.go Show resolved Hide resolved
ably/options.go Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 22, 2024 12:36 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 22, 2024 12:36 Inactive
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 049151c and 5254cae.

Files selected for processing (2)
  • ably/options.go (4 hunks)
  • ably/realtime_client_integration_test.go (3 hunks)
Additional comments not posted (3)
ably/realtime_client_integration_test.go (1)

138-165: Verify the correctness of the test cases.

The test cases in TestRealtime_RTN17_HostFallback appear to cover various scenarios for host fallback behavior. Ensure that the assertions are correctly validating the expected outcomes.

Run the following script to verify the correctness of the test cases:

Verification successful

Test cases are correctly validating host fallback behavior.

The test cases in TestRealtime_RTN17_HostFallback are comprehensive and correctly validate the expected outcomes for host fallback scenarios. The assertions are well-aligned with the expected conditions. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the test cases in `TestRealtime_RTN17_HostFallback`.

# Test: Search for test cases related to host fallback. Expect: Correct assertions and expected outcomes.
rg --type go -A 5 $'TestRealtime_RTN17_HostFallback'

Length of output: 447


Script:

#!/bin/bash
# Description: Capture the complete implementation of the `TestRealtime_RTN17_HostFallback` function.

# Use `ast-grep` to extract the full function implementation.
ast-grep --lang go --pattern 'func TestRealtime_RTN17_HostFallback(t *testing.T) {
  $$$
}'

Length of output: 11241

ably/options.go (2)

602-613: Verify the correctness of the URL and expected response.

The hasActiveInternetConnection function checks internet connectivity using a specific URL and expected response. Ensure that these values are correct and reliable.

Run the following script to verify the correctness of the URL and expected response:

Verification successful

URL and Expected Response Verified

The URL https://internet-up.ably-realtime.com/is-the-internet-up.txt and the expected response yes\n used in the hasActiveInternetConnection function are consistent and appear to be correct for checking internet connectivity.

  • ably/options.go: Uses the URL and checks for the response.
  • ably/realtime_client_integration_test.go: Also references the same URL.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the URL and expected response in the `hasActiveInternetConnection` function.

# Test: Check the definition of `internetCheckUrl` and `internetCheckOk`. Expect: Correct and reliable values.
rg --type go -A 1 $'internetCheckUrl|internetCheckOk'

Length of output: 762


489-493: Verify the usage of the realtimeHost parameter.

The realtimeURL function now accepts a realtimeHost parameter. Ensure that this change is correctly reflected in all parts of the codebase where the function is called.

Run the following script to verify the usage of the realtimeHost parameter:

Verification successful

Verified: Correct usage of the realtimeHost parameter

The realtimeURL function's new parameter realtimeHost is used correctly in the codebase. The function is called in ably/realtime_conn.go with the appropriate argument. No other instances of the function call were found, confirming consistent usage.

  • ably/realtime_conn.go: c.opts.realtimeURL(host)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `realtimeHost` parameter in the `realtimeURL` function.

# Test: Search for function calls to `realtimeURL`. Expect: Correct usage of the `realtimeHost` parameter.
rg --type go -A 2 $'realtimeURL'

Length of output: 382


Script:

#!/bin/bash
# Description: Search for all instances of the `realtimeURL` function to verify the usage of the `realtimeHost` parameter.

# Test: Find all calls to `realtimeURL` to ensure consistent usage of the `realtimeHost` parameter.
rg --type go 'realtimeURL\('

Length of output: 199

ably/error.go Show resolved Hide resolved
ably/options.go Outdated Show resolved Hide resolved
ably/options_test.go Show resolved Hide resolved
@sacOO7
Copy link
Collaborator Author

sacOO7 commented Aug 23, 2024

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented Aug 23, 2024

Actions performed

Comments resolved.

@sacOO7 sacOO7 requested a review from amnonbc August 23, 2024 04:35
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 23, 2024 16:57 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 23, 2024 16:57 Inactive
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5254cae and 4d846ed.

Files selected for processing (1)
  • ably/options.go (4 hunks)
Additional comments not posted (3)
ably/options.go (3)

34-36: LGTM! Constants for internet connectivity check are well-defined.

The constants internetCheckUrl and internetCheckOk are appropriately defined for checking internet connectivity.


491-495: LGTM! Function signature change enhances flexibility.

The realtimeURL function now accepts a realtimeHost parameter, allowing for more flexible usage.


604-616: LGTM! Internet connectivity check is well-implemented.

The hasActiveInternetConnection function is correctly implemented with proper error handling and resource management.

ably/options.go Show resolved Hide resolved
ably/realtime_client_integration_test.go Outdated Show resolved Hide resolved
@sacOO7 sacOO7 force-pushed the feature/realtime-fallbacks branch from 4d846ed to 22d35c9 Compare August 24, 2024 15:19
@github-actions github-actions bot temporarily deployed to staging/pull/657/godoc August 24, 2024 15:20 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/657/features August 24, 2024 15:20 Inactive
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d846ed and 22d35c9.

Files selected for processing (1)
  • ably/options.go (4 hunks)
Additional comments not posted (2)
ably/options.go (2)

491-495: Improved flexibility in realtimeURL method.

The change to accept a realtimeHost parameter enhances flexibility by allowing callers to specify the host directly. The updated comment clarifies the error handling purpose.


604-616: Well-implemented hasActiveInternetConnection method.

The method correctly uses a defer statement to close the response body, preventing resource leaks. It checks for a 200 status code and verifies the response body contains "yes", adhering to best practices.

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22d35c9 and 63cb110.

Files selected for processing (2)
  • ably/export_test.go (5 hunks)
  • ably/realtime_client_integration_test.go (3 hunks)
Additional comments not posted (4)
ably/export_test.go (3)

92-94: LGTM! But verify the value setting.

The code changes are approved.

However, ensure that the c.activeRealtimeHost value is correctly set elsewhere in the code.

Run the following script to verify the value setting:

Verification successful

Value Setting Verified for c.activeRealtimeHost

The value of c.activeRealtimeHost is set in the codebase:

  • File: ably/rest_client.go
  • Line: Assignment to realtimeHost

Ensure that the context of this assignment aligns with the intended logic of the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `c.activeRealtimeHost` is correctly set in the codebase.

# Test: Search for the value setting. Expect: Occurrences of setting `c.activeRealtimeHost`.
rg --type go 'c\.activeRealtimeHost\s*='

Length of output: 99


229-231: LGTM! But verify the value setting.

The code changes are approved.

However, ensure that the r.rest value is correctly set elsewhere in the code.

Run the following script to verify the value setting:

Verification successful

r.rest is correctly set in the NewRealtime function.

The r.rest field is assigned a value in the NewRealtime function, ensuring that the Rest method will return a properly initialized REST object.

  • Location:
    • ably/realtime_client.go: The NewRealtime function sets c.rest = rest.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `r.rest` is correctly set in the codebase.

# Test: Search for the value setting. Expect: Occurrences of setting `r.rest`.
rg --type go 'r\.rest\s*='

Length of output: 28


Script:

#!/bin/bash
# Description: Search for the initialization or assignment of `r.rest` and check for any constructors or methods that might set this value.

# Search for the initialization of `rest` in the `Realtime` struct.
rg --type go 'Realtime\s*\{[^}]*rest[^}]*\}'

# Search for any constructors or methods that might set `r.rest`.
rg --type go 'func\s+\w+\([^)]*\)\s*\*Realtime\s*\{'

Length of output: 101


Script:

#!/bin/bash
# Description: Broaden the search for any references to `rest` within the `Realtime` struct or any method that might set it.

# Search for any references to `rest` within the `Realtime` struct.
rg --type go 'rest' -A 5

# Search for any method that might set `rest`.
rg --type go 'func\s+\w+\([^)]*\)\s*\*Realtime\s*\{[^}]*rest[^}]*\}'

Length of output: 41273


124-126: LGTM! But verify the value setting.

The code changes are approved.

However, ensure that the opts.hasActiveInternetConnection value is correctly set elsewhere in the code.

Run the following script to verify the value setting:

ably/realtime_client_integration_test.go (1)

138-264: LGTM! But verify the test cases.

The code changes are approved.

However, ensure that the test cases are comprehensive and correctly implemented.

Run the following script to verify the test cases:

Verification successful

Comprehensive Test Cases Verified

The TestRealtime_RTN17_HostFallback function includes a comprehensive set of test cases that thoroughly cover various scenarios related to host fallback behavior. The implementation is well-structured and addresses multiple aspects of the functionality effectively.

  • The test cases cover default primary host attempts, fallback behavior, custom endpoint usage, fallback host provision, internet connection verification, error compatibility checks, and consistent fallback host usage for REST and Realtime.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the test cases in `TestRealtime_RTN17_HostFallback` are comprehensive and correctly implemented.

# Test: Search for the test cases. Expect: Occurrences of test cases in `TestRealtime_RTN17_HostFallback`.
rg --type go 'TestRealtime_RTN17_HostFallback'

Length of output: 140


Script:

#!/bin/bash
# Description: Analyze the test cases within `TestRealtime_RTN17_HostFallback`.

# Extract the lines of the function `TestRealtime_RTN17_HostFallback` to analyze the test cases.
rg --type go -A 50 'func TestRealtime_RTN17_HostFallback' ably/realtime_client_integration_test.go

Length of output: 2001


Script:

#!/bin/bash
# Description: Continue extracting lines from `TestRealtime_RTN17_HostFallback` to analyze all test cases.

# Extract additional lines from the function `TestRealtime_RTN17_HostFallback`.
rg --type go -A 100 'func TestRealtime_RTN17_HostFallback' ably/realtime_client_integration_test.go

Length of output: 4256

Copy link
Contributor

@amnonbc amnonbc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
LGTM.

@sacOO7 sacOO7 merged commit 673864c into main Aug 27, 2024
14 checks passed
@sacOO7 sacOO7 deleted the feature/realtime-fallbacks branch August 27, 2024 09:51
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.

RTN17: Host fallback
4 participants