Skip to content

[TEST] Add comprehensive DTLS socket test coverage#416

Merged
kcenon merged 2 commits into
mainfrom
feature/issue-401-dtls-test-coverage
Jan 11, 2026
Merged

[TEST] Add comprehensive DTLS socket test coverage#416
kcenon merged 2 commits into
mainfrom
feature/issue-401-dtls-test-coverage

Conversation

@kcenon

@kcenon kcenon commented Jan 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add test infrastructure for DTLS socket testing
  • Implement 20 unit tests for dtls_socket class
  • Achieve full test coverage for DTLS socket public interface

Changes

Test Infrastructure (tests/helpers/dtls_test_helpers.h)

  • ssl_context_wrapper: RAII wrapper for SSL_CTX with automatic cleanup
  • test_certificate_generator: Generate self-signed test certificates in memory
  • dtls_context_factory: Create server/client DTLS contexts for testing
  • find_available_udp_port: Port discovery utility for test isolation

Unit Tests (tests/unit/test_dtls_socket.cpp)

Construction Tests

  • ConstructWithValidContext - Verify socket creation with valid SSL context
  • ConstructWithNullContextThrows - Verify exception on null context
  • InitialStateNotHandshakeComplete - Verify initial handshake state

Callback Registration Tests

  • SetReceiveCallback - Test receive callback registration
  • SetErrorCallback - Test error callback registration
  • SetPeerEndpoint - Test peer endpoint configuration

Start/Stop Receive Tests

  • StartReceiveDoesNotThrow - Verify safe start receive
  • StopReceiveDoesNotThrow - Verify safe stop receive
  • MultipleStartReceiveCalls - Test idempotent start
  • MultipleStopReceiveCalls - Test idempotent stop

Handshake Tests

  • ClientServerHandshake - Full client-server DTLS handshake
  • SendBeforeHandshakeFails - Verify send fails before handshake

Thread Safety Tests

  • ConcurrentCallbackRegistration - Test thread-safe callback registration
  • ConcurrentEndpointAccess - Test thread-safe endpoint access

Integration Tests

  • SendReceiveAfterHandshake - Data exchange after handshake
  • BidirectionalCommunication - Two-way data exchange
  • LargePayload - Test with 1000-byte payloads

Error Handling Tests

  • ErrorCallbackInvokedOnSocketClose - Verify error callback on socket close
  • SocketAccessReturnsValidSocket - Verify socket accessor
  • DestructorAfterStartReceive - Test cleanup after async operations

Test Results

All 20 tests pass:

[==========] Running 20 tests from 2 test suites.
[  PASSED  ] 20 tests.

Test plan

  • All unit tests pass locally
  • Build passes with TLS support enabled
  • No memory leaks (RAII patterns used throughout)
  • Thread safety tests pass

Closes #401

Implement test infrastructure and unit tests for dtls_socket class:

- Add dtls_test_helpers.h with:
  - ssl_context_wrapper: RAII wrapper for SSL_CTX
  - test_certificate_generator: In-memory self-signed cert generation
  - dtls_context_factory: Server/client DTLS context creation
  - find_available_udp_port: Port discovery utility

- Add test_dtls_socket.cpp with 20 test cases covering:
  - Construction (valid context, null context throws)
  - Callback registration (receive, error, endpoint)
  - Start/stop receive operations
  - Send before handshake failure
  - Client-server handshake
  - Thread safety (concurrent callbacks, endpoint access)
  - Send/receive after handshake
  - Bidirectional communication
  - Large payload handling
  - Error callback on socket close

- Update CMakeLists.txt to include DTLS socket tests

All 20 tests pass successfully.

Closes #401
Add entry for issue #401 in both English and Korean changelogs
documenting the new DTLS test infrastructure and unit tests.
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

@codecov

codecov Bot commented Jan 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.19%. Comparing base (a4d8129) to head (d5cd0e1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #416      +/-   ##
==========================================
+ Coverage   32.94%   33.19%   +0.24%     
==========================================
  Files          39       39              
  Lines        2841     2841              
==========================================
+ Hits          936      943       +7     
+ Misses       1905     1898       -7     
Flag Coverage Δ
unittests 33.19% <ø> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kcenon kcenon merged commit 9ec5fce into main Jan 11, 2026
43 checks passed
@kcenon kcenon deleted the feature/issue-401-dtls-test-coverage branch January 11, 2026 16:14
kcenon added a commit that referenced this pull request Apr 13, 2026
* Add comprehensive DTLS socket test coverage

Implement test infrastructure and unit tests for dtls_socket class:

- Add dtls_test_helpers.h with:
  - ssl_context_wrapper: RAII wrapper for SSL_CTX
  - test_certificate_generator: In-memory self-signed cert generation
  - dtls_context_factory: Server/client DTLS context creation
  - find_available_udp_port: Port discovery utility

- Add test_dtls_socket.cpp with 20 test cases covering:
  - Construction (valid context, null context throws)
  - Callback registration (receive, error, endpoint)
  - Start/stop receive operations
  - Send before handshake failure
  - Client-server handshake
  - Thread safety (concurrent callbacks, endpoint access)
  - Send/receive after handshake
  - Bidirectional communication
  - Large payload handling
  - Error callback on socket close

- Update CMakeLists.txt to include DTLS socket tests

All 20 tests pass successfully.

Closes #401

* Update CHANGELOG for DTLS socket test coverage

Add entry for issue #401 in both English and Korean changelogs
documenting the new DTLS test infrastructure and unit tests.
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.

[TEST] Add comprehensive DTLS socket test coverage

1 participant