Skip to content

Improve RPC and WebSocket test reliability and error handling#128

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/improve-rpc-websocket-test-reliability
Draft

Improve RPC and WebSocket test reliability and error handling#128
Copilot wants to merge 2 commits intomainfrom
copilot/improve-rpc-websocket-test-reliability

Conversation

Copy link

Copilot AI commented Mar 13, 2026

Both test scripts had silent failure modes: rpc_test.py swallowed RPC-level errors (e.g. {"error": {"code": -32000}}), and websocket_test.py could loop indefinitely with no exit criteria or CI-detectable failure signal.

rpc/rpc_test.py

  • Assert HTTP 200 on all requests
  • Validate response JSON has result and no error field — RPC-level errors now surface as failures
  • test_chain_id parses and validates the returned hex chain ID against the expected value
  • Network exceptions wrapped in AssertionError instead of being silently printed
  • sys.exit(1) on any failure; all tests run and report individually before exit

rpc/websocket_test.py

  • Replaced infinite while True loop with a bounded loop: exits when min_events received or total_timeout elapsed
  • time.monotonic() deadline passed directly to asyncio.wait_for — single clean timeout, no restart-loop
  • Subscription response validated for error field
  • Added --timeout (default 120s) and --min-events (default 1) CLI args
  • asyncio.gather(..., return_exceptions=True) isolates per-endpoint failures
  • sys.exit(0/1) for CI/CD pipeline detection
# Configurable timeout and success threshold
python websocket_test.py --timeout 60 --min-events 3
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][Medium] Improve RPC and WebSocket test reliability and error handling</issue_title>
<issue_description>## Summary

The Python RPC and WebSocket test scripts have weak error handling patterns that can mask failures and cause test processes to hang indefinitely.

Affected Files

1. rpc/rpc_test.py (Lines 20-22, 34-36)

Issue: Generic exception catching with no response validation.

except Exception as e:
    print(f"Connection failed, Error: {str(e)}")
    # Does not validate response JSON structure or check for RPC error fields

Impact: Tests can report "pass" even when the RPC endpoint returns error responses, because only connection-level failures are caught. RPC-level errors (e.g., {"error": {"code": -32000}}) are silently ignored.

Suggested fix:

  • Validate response JSON has expected fields (result, not error)
  • Use assert statements or a proper test framework (pytest)
  • Check HTTP status codes explicitly

2. rpc/websocket_test.py (Lines 18-26)

Issue: Infinite loop with silent timeout swallowing.

while True:
    try:
        message = await asyncio.wait_for(ws.recv(), timeout=60)
        print(json.loads(message))
    except asyncio.TimeoutError:
        pass  # Silently continues — loop never exits naturally
    except Exception as e:
        break

Impact: If the WebSocket subscription produces no events, the test loops forever (each iteration waits 60 seconds then restarts). There is no maximum iteration count, no total timeout, and no success/failure exit criteria.

Suggested fix:

  • Add a maximum number of iterations or a total elapsed time limit
  • Define explicit success criteria (e.g., "received at least N events")
  • Exit with appropriate exit code (0 for success, 1 for timeout/failure)
  • Add --timeout CLI argument for configurable test duration

General Recommendations

  • Migrate both test files to use pytest with proper assertions
  • Add sys.exit(1) on failure so CI/CD pipelines can detect test failures
  • Add type checking for received JSON payloads
  • Document expected test behavior in docstrings

Generated by Health Monitor with Omni</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature] Improve RPC and WebSocket test reliability and error handling Improve RPC and WebSocket test reliability and error handling Mar 13, 2026
Copilot AI requested a review from numbers-official March 13, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][Medium] Improve RPC and WebSocket test reliability and error handling

2 participants