Skip to content

Add protocol error detection and improve test isolation#59

Merged
ruoso merged 1 commit intoPacktPublishing:mainfrom
ruoso:more-codegen
Dec 13, 2025
Merged

Add protocol error detection and improve test isolation#59
ruoso merged 1 commit intoPacktPublishing:mainfrom
ruoso:more-codegen

Conversation

@ruoso
Copy link
Copy Markdown
Collaborator

@ruoso ruoso commented Dec 9, 2025

Code Generator:

  • Add has_error_ flag to generated state machines to track protocol mismatches
  • Detect when received data doesn't match any expected message format
  • Add has_error() method to ServerRunner to expose error state

libuv Wrapper:

  • Add has_error() to IConnectionRunner interface
  • Check for protocol errors in on_read and on_write_complete callbacks
  • Close connections gracefully when protocol errors are detected

Test Infrastructure:

  • Update tests to use unique directories under build dir (TEST_BUILD_DIR)
  • Prevents conflicts when running tests in parallel with -j8
  • Add NETWORKPROTOCOLDSL_UV_INCLUDE_DIR and NETWORKPROTOCOLDSL_UV_LIB_DIR

New Integration Tests:

  • test_full_email_transaction: Complete SMTP email flow
  • test_multi_connection: Multiple concurrent connections
  • test_protocol_mismatch: Protocol error detection using GeneratedServerWrapper

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds protocol error detection capabilities to the generated state machines and improves test isolation for parallel execution. The code generator now tracks protocol mismatches when received data doesn't match expected message formats, and the libuv wrapper gracefully closes connections on errors.

Key Changes:

  • Added has_error_ flag and detection logic to generated state machines to identify protocol violations
  • Enhanced libuv wrapper with error checking in I/O callbacks and graceful connection closure
  • Implemented unique test directories using test name + PID to enable safe parallel test execution with -j8

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/networkprotocoldsl/codegen/generate_state_machine.cpp Adds error detection logic that sets has_error_ when parsers fail to make progress on received data
src/networkprotocoldsl/codegen/generate_runner.cpp Exposes has_error() method in ServerRunner to check protocol error state
src/networkprotocoldsl_uv/generatedserverwrapper.hpp Adds has_error() to IConnectionRunner interface
src/networkprotocoldsl_uv/generatedserverwrapper.cpp Implements protocol error checking in read/write callbacks with graceful connection closure
tests/CMakeLists.txt Adds TEST_BUILD_DIR and library path definitions for test isolation
tests/038-codegen-integration-test.cpp Creates unique test directories using test name + PID for parallel execution safety
tests/037-codegen-compile-smtp.cpp Implements unique directory naming with timestamp for test isolation
tests/data/codegen/test_full_email_transaction.cpp New integration test verifying complete SMTP email transaction flow
tests/data/codegen/test_multi_connection.cpp New test validating concurrent connection handling with independent state machines
tests/data/codegen/test_protocol_mismatch.cpp New test ensuring protocol errors are detected and connections closed gracefully

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Code Generator:
- Add has_error_ flag to generated state machines to track protocol mismatches
- Detect when received data doesn't match any expected message format
- Add has_error() method to ServerRunner to expose error state

libuv Wrapper:
- Add has_error() to IConnectionRunner interface
- Check for protocol errors in on_read and on_write_complete callbacks
- Close connections gracefully when protocol errors are detected

Test Infrastructure:
- Update tests to use unique directories under build dir (TEST_BUILD_DIR)
- Prevents conflicts when running tests in parallel with -j8
- Add NETWORKPROTOCOLDSL_UV_INCLUDE_DIR and NETWORKPROTOCOLDSL_UV_LIB_DIR

New Integration Tests:
- test_full_email_transaction: Complete SMTP email flow
- test_multi_connection: Multiple concurrent connections
- test_protocol_mismatch: Protocol error detection using GeneratedServerWrapper
@ruoso ruoso merged commit fce7278 into PacktPublishing:main Dec 13, 2025
1 check passed
@ruoso ruoso deleted the more-codegen branch December 13, 2025 18:56
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.

2 participants