-
Notifications
You must be signed in to change notification settings - Fork 403
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
Iox #337 deprecate posix timer #479
Iox #337 deprecate posix timer #479
Conversation
This PR contains only the code related to the deadline use case. The Keep alive use case from @elBoberido will be adapted in the following PR. |
class Timer | ||
{ | ||
private: | ||
iox::units::Duration m_measuringDuration; | ||
iox::units::Duration m_startTime; | ||
|
||
iox::units::Duration getCurrentMonotonicTime() noexcept; | ||
|
||
public: | ||
/// @brief Checks if the timer has expired compared to its start time | ||
/// @return Is the elapsed time larger than duration set | ||
bool hasTimerExpired() noexcept; | ||
|
||
Timer(const iox::units::Duration) noexcept; | ||
|
||
/// @brief reinitializes the starting time for the timer to the current time | ||
void resetDurationTimer() noexcept; | ||
}; |
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.
could you move this to iceoryx_utils/cxx
and rename it to DeadlineTimer
. Other frameworks call it also this way, e.g. QDeadlineTimer. I think an additional namespace is not necessary.
@MatthiasKillat @mossmaurice @dkroenke what do you think?
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.
Yes I can rename this to deadline timer. The reason behind the new namespace introduction was the time calculations are based on the std::chrono and not using the POSIX apis.
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.
DeadlineTimer is fine and reflects its functionality. The namespace cxx is ok for now, but we may need to differentiate between reimplementing STL (like) constructs and creating other useful helper classes in the long run. The DeadlineTimer would then belong into the second category.
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.
@MatthiasKillat you have to think big. The STL has to add the stuff we put into the cxx namespace ;)
@dkroenke what do you think about moving this to cxx? It doesn't have any POSIX dependency anymore
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.
Looks OK functionally, only optional style remarks from my side.
@@ -321,6 +321,36 @@ class Timer | |||
}; | |||
|
|||
} // namespace posix | |||
|
|||
// IOX-#337 Alternate Timer to replace the POSIX timer |
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.
please make a /// @note
of that
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.
or maybe even better make an @brief
with a small description. In one year nobody cares that this functionality was in POSIX Timer
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.
Can you make the class comment more descriptive ?
What does it mean to be a deadline timer ? How do I use it ?
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.
Okay added more descriptions for the class
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.
Also, this file should be renamed to deadline_timer.hpp
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.
no, the functionality needs to be moved to a new file. This file will contain a new timer which just wraps a semaphore and does a blocking wait until it's either interrupted or timed out. It will be used in PeridoicTask
, which in combination with the new timer provides the functionality of the execution of a callback from the old timer.
The semaphore might later on be replaced by a timer_create
call, but instead of spawning a thread, it will just block, like the semaphore and if someone needs a separate thread, the PeriodicTask
should be used.
@shankar-bosch I just noticed that your commit messages are not according our [guidelines] (https://github.com/eclipse-iceoryx/iceoryx/blob/master/CONTRIBUTING.md) @nihalchari wasn't the PR template shown when created the PR? |
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.
Logic is fine. Just need to rename the timer file & add class documentation.
@@ -321,6 +321,36 @@ class Timer | |||
}; | |||
|
|||
} // namespace posix | |||
|
|||
// IOX-#337 Alternate Timer to replace the POSIX timer |
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.
Can you make the class comment more descriptive ?
What does it mean to be a deadline timer ? How do I use it ?
@@ -321,6 +321,36 @@ class Timer | |||
}; | |||
|
|||
} // namespace posix | |||
|
|||
// IOX-#337 Alternate Timer to replace the POSIX timer |
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.
Also, this file should be renamed to deadline_timer.hpp
/// @brief Class which offers the deadline timer functionality | ||
/// @note This class is introduced as an alternate timer functionality for the deprecated POSIX timers | ||
/// | ||
/// @code |
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.
Nice !
@ithier I havent renamed the file because currently this PR still keeps the deprecated methods for posix timers. once this is tested and removed the file would be renamed and moved out of the posix wrappers. |
Working on the failing test. |
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.
please rework the RemainingTimeCheckIfNotExpired test
|
||
sut.reset(20_s); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(2 * TIMEOUT.milliSeconds<int>())); | ||
EXPECT_THAT(sut.remainingTime(), Le(TIMEOUT)); |
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 test will not work because you reset the timer with 20 Seconds and expect then a value lower or equal to 20 milliseconds after waiting 40 milliseconds. The logic is also incorrect because the test would also pass if no time has passed (Lower equal)
Proposal:
- create a timer and wait for a defined time
- get the remaining time
- check if the result is in a range ±10 percent from the expected value
You need to make a range because the test could flicker due to the non-deterministic Github CI.
For an example please take a look at TIMING_TEST_F(Timer_test, RestartWithDifferentTiming)
in line 237 of this file.
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.
could you also please remove the obsolete methods like hasExpiredComparedToCreationTime
from the old timer class
@elBoberido it was there. @shankar-bosch could u please change this commit message "iox-337: initial commit for deadline impl " to "iox-#337 initial commit for deadline impl " Also hyphen - used after issue no can be replaced with space in following commits |
I have 3 stories created for POSIX timer,
Removing of the deprecated methods comes in part 3. where the timer will also be moved out of the posix wrapper package to a new class. Is this okay? |
@shankar-bosch sounds like a plan, please add these three points to the issue #337 or ask @marthtz to do it, because he is the issue owner. |
|
@shankar-bosch if this would be a big change I would agree, but since you already ported the code to the new class it doesn't make sense to keep the old code around and it's also not much to delete. I also object to merge this with the new class in the old file. It's not much work to move it to an own file and have it clean from the beginning. If you plan t do bigger changes I always suggest to create one PR with only the new class and tests and another one with integration of the class and maybe removing of old code. |
@elBoberido |
@shankar-bosch sorry, but this is about getting clean code to master and it's not something that takes hours or days to accomplish. It's not additional functionality, just moving new code to a dedicated location and removing dead code. Sorry if this sounds harsh. It's not intended. |
@elBoberido Not at all. I was informed that POSIX timers goes for 1.0 which is scheduled for March with low prio. It was planned by splitting in parts during the refinement and take up across sprints. |
@shankar-bosch so according to your plan this situation might last until march. That's one more reason not to merge this to master in the current form. This increases the technical dept for no good reason. What happens if you get assigned to another task or, hopefully not, get ill? Then this situation remains even longer. Your PR is neither too big nor does is constantly get merge conflicts due to other PRs nor does it take long to accomplish the requested changes. Seriously, I don't understand the problem. |
@elBoberido I dont have. I agree with your points completely. Spoke with the team already. I am working on this review point now. Sorry for any confusion caused. |
Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
4c801b3
@elfenpiff I have signed all my commits pls verify and approve this PR |
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.
Could you please add some additional test cases.
const Duration DeadlineTimer_test::TIMEOUT{10_ms}; | ||
const int DeadlineTimer_test::SLEEPTIME = DeadlineTimer_test::TIMEOUT.milliSeconds<int>(); | ||
|
||
TIMING_TEST_F(DeadlineTimer_test, DurationOfNonZeroIsExpiresAfterTimeout, Repeat(5), [&] { |
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.
What if the Deadline timer has a timeout of zero? Is the Callback then called as fast as possible? We should also always keep the following test ideas in mind:
- Zero
- One
- Many
- Corner Cases
- Limits
to cover every aspect of a class.
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 is only the deadline timer use case. in case if the timer has a duration set to zero the end time will be the current time and the timer will be already expired. I can add a test case for this.
TIMING_TEST_EXPECT_FALSE(sut.hasExpired()); | ||
}); | ||
|
||
TIMING_TEST_F(DeadlineTimer_test, ResetWithCustomizedTimeAfterBeingExpiredIsNotExpired, Repeat(5), [&] { |
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.
Could you please write the same test for the case when the time is not being expired.
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.
Okay
}); | ||
|
||
|
||
TIMING_TEST_F(DeadlineTimer_test, RemainingTimeCheckIfNotExpired, Repeat(5), [&] { |
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.
Could you please write a test where you verify that the remaining time is zero when the timer is expired.
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.
Okay
Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
c4c6c06
…ine timer Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
const int EXPECTED_REMAINING_TIME = PASSED_TIMER_TIME - RANGE_APPROX; | ||
|
||
TIMING_TEST_EXPECT_TRUE(remainingTime >= EXPECTED_REMAINING_TIME && remainingTime <= PASSED_TIMER_TIME); | ||
}); |
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.
Missing newline at end of file?
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.
Added a new line to the end of file
Signed-off-by: Sankara Narayanan Chandrasekar (RBEI/EMT2) <[email protected]>
@elfenpiff Could you pls check whether your review comments are addressed and approve if you are okay with the changes? |
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.
@shankar-in Thank you for the good work.
@elBoberido Thanks a lot! |
Pre-Review Checklist for the PR Author
iox-#123-this-is-a-branch
)iox-#123 commit text
)git commit -s
)Notes for Reviewer
code contributed by @shankar-bosch
Checklist for the PR Reviewer
Post-review Checklist for the PR Author
Post-review Checklist for the Eclipse Committer
References