Skip to content

Enhance connection_panic_is_caught test to assert on panic log output #216

@coderabbitai

Description

@coderabbitai

Context

This issue is a follow-up to PR #215 which implemented panic handling improvements for connection tasks. The current test connection_panic_is_caught verifies that the server doesn't crash when connection tasks panic, but it doesn't verify that the panic logging works correctly.

Current Implementation

The panic handling code in src/server.rs logs panics with peer address context:

let peer_addr = stream.peer_addr().ok();
// ... spawn task with catch_unwind
tracing::error!("Connection task panicked: {:?}, peer_addr: {:?}", panic_info, peer_addr);

However, the test doesn't assert that this log message is actually emitted with the expected peer address.

Proposed Solution

Enhance the test to capture and assert on log output:

  1. Use a test log harness (e.g., tracing-test crate or similar) to capture log messages during the test
  2. Assert on log content - verify that the panic log contains:
    • The expected panic message/info
    • The peer address of the connection that panicked
  3. Improve test reliability - ensure the test validates the complete panic handling behavior

Potential Implementation

#[tokio::test]
async fn connection_panic_is_caught() {
    // Setup log capturing
    let (log_guard, log_receiver) = setup_test_logs();
    
    // Existing test setup...
    
    // Trigger panic scenarios...
    
    // Assert on captured logs
    let logs = log_receiver.try_recv().unwrap();
    assert!(logs.iter().any(|log| {
        log.level == Level::ERROR &&
        log.message.contains("Connection task panicked") &&
        log.message.contains("127.0.0.1") // or expected peer addr
    }));
}

Benefits

  • Test completeness: Verifies the entire panic handling flow including logging
  • Regression prevention: Ensures log format and content remain correct
  • Documentation: Shows expected log output format for operators

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions