-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix warnings in tcp/udp UT #2744
base: devel
Are you sure you want to change the base?
Fix warnings in tcp/udp UT #2744
Conversation
@@ -72,13 +72,15 @@ void SocketReadTask::readTask(void* pointer) { | |||
SocketIpStatus status = SOCK_SUCCESS; | |||
SocketReadTask* self = reinterpret_cast<SocketReadTask*>(pointer); | |||
do { | |||
self->m_task_lock.lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense!
if (recv_thread) { | ||
//this->component.close(); | ||
if ((1 + i) == iterations) { | ||
this->component.m_task_lock.lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These locks should be done in the shutdown and close methods, not just the UT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the mutex in the close/shutdown functions. I had to update the TcpServerTester.cpp
a bit for it to work: the client needs to be closed after the server is closed. I do not have the explanation for this behavior, but otherwise I was getting the following warning:
Connected to 127.0.0.1:57755 as a tcp client
Accepted client at 127.0.0.1:57755
[WARNING] Failed to recv from port with status -8 and errno 0
There was a comment stating: // Client must be closed first or the server risks binding to an existing address
. Let me know if it is a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added the muted on the stop function. Can you confirm that it is something that is expected?
@LeStarch is there something we can do in the UT to check that no warnings are logged using During my tests, I used that warning messages to realize that something was wrong. I also used a timeout to make sure that the tests were not taking too long. It was especially useful for checking that the TcpServer tests were working properly. The test could take a few seconds on failure, where it's supposed to be less than 500ms in nominal conditions on my hardware. However, I don't think that's something that can/should be implemented, since it's hardware dependent. |
// Properly stop the client on the last iteration | ||
if ((1 + i) == iterations && recv_thread) { | ||
this->component.shutdown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LeStarch Can you confirm that we do not need this shutdown
, since it's already part of the stop
function?
Keeping it is causing a timeout on my setup (the UT tasking more than 1s)
@LeStarch @thomas-bc Let me know if there is something else to change in this PR |
Change Description
I am not sure we want to have those changes in the codebase. That could be used as a baseline for a better update.
Most of the warnings in the UT with TCP/UDP module should be fixed with those changes. A mutex is making sure that the receive/open/startup functions are called only if the stop/close function are not going to be called in an other thread.
I added the changes in the unit tests instead of the class itself (in open/close), because I did not find a way to make it work properly.
I also needed to make
recv
to stop iterating iferrno == EAGAIN
to avoid a timeout. I'm not sure if that's the proper way to fix this issue.The only warning still happening for me, after 10.000 tests, is the following (happened only once):
I feel like the warnings in the test should make the UT to fail. However, I am not sure how to catch the warning streamed through
Fw::Logger::logMsg
.Also fix an error in
StringUtils.cpp
when compiled on ubuntu20.04 with a FW_ASSERT: