-
Notifications
You must be signed in to change notification settings - Fork 2
KF-30 add tests for Event #67
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
Conversation
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.
Pull Request Overview
This PR adds comprehensive unit tests for the kf::Event class, covering both NotificationEvent and SynchronizationEvent types with various scenarios including timeouts, multiple waiters, and state management operations.
- Adds extensive test coverage for Event functionality including initialization, setting/clearing states, waiting with/without timeouts
- Implements multi-threaded tests to verify proper synchronization behavior between NotificationEvent and SynchronizationEvent types
- Integrates the new test file into the CMake build system
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/EventTest.cpp | New comprehensive test file covering Event class functionality with single and multi-threaded scenarios |
| test/CMakeLists.txt | Adds EventTest.cpp to the build configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
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.
Tests with another thread have a fatal flaw: a thread is not started right away, it takes an arbitrary time to spin up a thread. I suggest just to call wait() in the main thread. It should be able to cover necessary cases (and be simpler).
|
@SergiusTheBest but if I just call wait() it in the main thread, it will hang waiting forever |
@Kellesi No, if you set 0 timeout. |
|
@SergiusTheBest timeout 0 won't actually wait, it just checks the current state and returns immediately. That makes it impossible to test cases where a thread should really be blocked on an Event. That means we cannot test scenarios where threads are supposed to wait and later be released - for example, verifying that only one thread wakes up for a SynchronizationEvent, or that all waiters are released for a NotificationEvent. |
@Kellesi - We don't test it even now having multiple threads as we signal an event before a thread begins waiting. I suggest to trust the OS in terms of thread scheduling and focus on the event state and transitions. And for that wait(() with 0 timeout is sufficient. It can check every test case we have now. |
|
@Kellesi An example (I didn't update step description): GIVEN("NotificationEvent with multiple waiters and NotificationEvent for complition")
{
kf::Event triggerEvent(NotificationEvent, false);
WHEN("A wait is performed with no timeout and the event is not set")
{
THEN("Both threads are waiting")
{
REQUIRE(STATUS_TIMEOUT == triggerEvent.wait(&kZeroTimeout));
REQUIRE(STATUS_TIMEOUT == triggerEvent.wait(&kZeroTimeout));
}
triggerEvent.set();
THEN("After trigger event is set, both threads are released from waiting")
{
REQUIRE(STATUS_SUCCESS == triggerEvent.wait(&kZeroTimeout));
REQUIRE(STATUS_SUCCESS == triggerEvent.wait(&kZeroTimeout));
}
}
} |
ba99ed2 to
6bd3916
Compare
|
Removed threads from the last two tests, but kept it for the test case that checks waiting with timeout = nullptr. |
Task: https://jira.dev.local/jira/browse/KF-30