Tomas/connection raii initial#413
Draft
ProfessorTom wants to merge 275 commits into
Draft
Conversation
ProfessorTom
force-pushed
the
tomas/connection-raii-initial
branch
2 times, most recently
from
March 7, 2026 01:44
81ffa3c to
c4d8576
Compare
ProfessorTom
force-pushed
the
tomas/connection-raii-initial
branch
from
May 25, 2026 22:17
1c8340b to
99d2b79
Compare
This constructor will be used by Connection Manager for incoming/server connections
- Moves initialization of closeRequest from run() to member declaration - Eliminates redundant assignment and prevents uninitialized-read warnings - Improves code clarity and maintainability (C++11+ in-class initializer)
if all the tests pass, tell us that if there are failures, tell us that Qtest doesn't do this automatically. It prints successes and failures per file. It needs a test reporter.
…bleWaitForReadyRead()` calls
…esn't work on `QDEBUG()`
- Use state_ instead of thread_ checks in isConnected() - Update terminateConnection() - Add proper destructor - Remove immediate thread_.reset()
- Add hasConnection() - Add create*Object() factory methods - Use mutex in close() - Safer disconnected handler
- Add testDefaultStateIsCreated() - Add testTerminate_TransitionsStateToClosing_whenThreadIsNullptr() - Add testTerminate_TransitionsStateToClosed_whenThreadIsNOTNullptr() - Update ConnectionTests class These tests verify basic state transitions in the new Connection state machine.
- testHandleOutgoingPlainTCP_success_setsConnectionStateToActive() - testHandleOutgoingPlainTCP_unsuccessful_setsConnectionStateToInactive() These tests verify that the Connection state machine correctly updates on successful and unsuccessful send() operations using the test double.
- Add testSocketSuccessfullySetsSocketDescriptor_TransitionsStateToActive() - Add testSocketDisconnectedBeforeIncomingDataRead_TransitionsStateToInactive() - Extend IncomingTcpConnectionTestDouble with socket configuration options - Add more message mappings in BaseTcpConnection::stateFromMessage() These changes improve test coverage for the Connection state machine, especially for incoming connections.
…uration - Added `testIncomingSSL_failure_setsConnectionStateToInactive()` - Extended `IncomingTcpConnectionTestDouble` with `HANDLE_INCOMING_SSL_FAILURE` case - Added `createSslFailure()` helper that simulates SSL handshake failure (self-signed certificate error) - Updated state mapping in `BaseTcpConnection` for `SSL_HANDSHAKE_FAILED`
- Replace `createMockSocketForTest()` with `createMockSocketWithSocketDescriptorOtherThan0()` in tests - This avoids socket descriptor 0 errors in IncomingTcpThread constructor - Update MockSslSocket and TestUtils with new helper - Minor test cleanups and debug improvements This resolves several test failures related to socket descriptor validation.
- testHandleOutgoingSSL_success_setsConnectionStateToActive() - testHandleOutgoingSSL_failure_setsConnectionStateToInactive() - Extend OutgoingTcpConnectionTestDouble with SSL success/failure configurations - Update test runner and supporting test utilities This improves test coverage for SSL handshake paths in the Connection state machine.
- Add signalSpyCountMessage*() helpers - Add TestUtils::toString(Connection::State)
…e in the debug output. (saves 1.5 days trying to figure out where the app is crashing.)
- Add setState() method - Update stateFromMessage() with more mappings - Skip redundant "Sending data" state changes - Better default state on unknown message
- Emit proper ConnectionStatusMessages on SSL success/failure - Minor debug logging improvements
- Add states vector and printStates() in test doubles - Override setState() to record state transitions - Improve SSL configuration options in test doubles
- Replace direct state checks with vector-based assertions - Use new signalSpyCountMessage helpers where appropriate - Update test setup for socket descriptor validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting a pull request:
This will likely be a Cthulhu PR that will need to be broken up into a few smaller PRs once the work is done. Unfortunately, the way through is a long running branch in the short term.
Some benefits and thoughts as work continues on this branch:
TcpThreadclass will be replaced withBaseTcpThread,OutgoingTcpThreadandIncomingTcpThread.The idea here is to combine common code in the base class but separate the different directions so that they have room to breath and you can follow the main flows more easily. All three of those classes will automagically clean up both the socket and the threads via RAII and Qt's object lifecycle and parenting system.
There will be a root
Connectionclass, aBaseTcpConnectionclass, anIncomingTCPConnectionand anOutgoingTcpConnectionclass.Here's the basic idea:
Connection (abstract)
│
├── BaseTcpConnection
│ ├── OutgoingTcpConnection
│ └── IncomingTcpConnection
│
├── BaseDtlsConnection
│ ├── OutgoingDtlsConnection
│ └── IncomingDtlsConnection
│
├── BaseUdpConnection
│ └── UdpConnection (usually no separate in/out)
│
└── ... (future protocols: RS-232 [aka Serial] QUIC, WebSocket, SCTP, etc.)
Unit tests have been added for code I have modified or added and will continue to be added for code I modify or add.
qMake is likely going away.
I'm not sure how Dan builds for each platform.
I was under the impression that most if not all platforms were using CMake now. I know snapcraft and macOS does. Regardless, the unit test only work with CMake, in part, because I am developing on a Mac. There may be some way to get the unit tests to build and run with qMake, but as I understand it, Dan wanted to move away from qMake anyway, so now's the chance.
This means I should be able to delete the .pro files in this PR.
At the time of this writing I am not doing so because I don't know what the consequences are for taking that action. e.g. there may be one build that is still using qMake.I talked with @dannagle and he said that Windows stills needs to be converted to CMake. I know that the snapcraft build uses CMake. Not sure about the Debian build in the pipeline.This likely means modifying the build process to build and run the unit tests and perhaps have such failures block PR merges. While the latter can be done once here on GitHub, the former will have to be done on each platform that PacketSender is built for. Given we are dealing with some low-level functionality (e.g. IPv4 vs IPv6, os default network stacks, etc.), it's possible that some unit tests may fail on platforms other than macOS. I haven't tested on any other platform. I fully intend for this to be a problem for Dan to solve, not because I'm being lazy or want to give Dan more work, but because at the time of this writing, this PR is not complete and I don't have access to each build system to test them.
Fixes #151