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:
- Use a test log harness (e.g.,
tracing-test crate or similar) to capture log messages during the test
- Assert on log content - verify that the panic log contains:
- The expected panic message/info
- The peer address of the connection that panicked
- 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
Context
This issue is a follow-up to PR #215 which implemented panic handling improvements for connection tasks. The current test
connection_panic_is_caughtverifies 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.rslogs panics with peer address context: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:
tracing-testcrate or similar) to capture log messages during the testPotential Implementation
Benefits
References