tests: coap_client: optimize/reduce sleep time #79369
Open
+156
−164
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.
The goal of this commit is to reduce the overall test time by optimizing the time spent sleeping as suggested here: #78904 (comment).
However while doing so, a few glitches became apparent and those have been fixed as well.
In most tests, the event would stick for the whole test and this would sometimes results in the client receiving more data than intended which in turn would results in various unexpected warnings and errors.
The management of the ZSOCK_POLLIN event has now been mostly moved to the send/receive overrides which better represent how things would happen outside of the test scenario.
For example, when sending data, if this send would normally result in receiving some response, the send function sets the ZSOCK_POLLIN event. Then when receiving, we clear the event as the data has been received.
There are a few exceptions to this for cases where we need to simulate some specific abnormal behavior.
messages_needing_response
queue now includes a valid bitThe test manages a queue of messages id to be able to respond to the correct id in the receive hooks.
It was built in a way that the id 0 would be treated as invalid although it is a valid id.
In practice, it would not be an issue in most cases however, it would result in an unexpected behavior if the
test_multiple_requests
test would be run first.To fix this issue in the simplest way, the queue has been changed to uint32_t which gives us 16 extra bits for the management of the queue, 1 of which is used to tell if the entry is valid or not.