-
-
Notifications
You must be signed in to change notification settings - Fork 89
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: Use SystemTime instead of Instant everywhere #5108
Conversation
I'm going to mock the system clock in some way for the tests so that we can write tests checking timestamps of messages and this is some preparational work. The reason is that we already have some fixes like #5094 that are not covered by any tests because such tests would need large sleep()s currently |
did not look closely to the pr, just by the title: InstantTime had issues in the past, therefore we switched to SystemTime: #1706 only tests seems to be a weak reason to change these things, that could maybe achieved also differently. do we really have bugs wrt time? if so, i'd fix them more on-point; it seems to be so easy to break things in this area :) otherwise, never change a running system :) |
You're right, the issue with As for the second commit, it doesn't change much, i only cache a system time value if it's used several times in a function and isn't supposed to change. In some places it's already done currently, i just want the same approach to be used everywhere. |
b0f2267
to
d7f8d17
Compare
Switched to using At least, now it's clear where a real monotonic clock should be used, but can't be used currently. |
0029cfc
to
d7f8d17
Compare
I'm not sure we should call it For the case that you haven't seen it already: tokio has some support for mocking the system time, maybe it's helpful. For the second commit, are there any reports that there are problems with decreasing time? |
It is not going to be solved according to the discussion and it is impossible to solve on Android 4.1 phones with kernels that don't support |
Ok, agree with this.
There are probably no such reports, but some functions cache the system time in a var named e.g.
So, we're not going to get rid of using |
I checked the @r10s's commit again and as i see the initial idea was to get rid of |
3d64d75
to
8ed0d33
Compare
For some reason i only see Btw, there's another problem with mocking the system time for tests -- they run in parallel and a system time adjustment in one test can break another one. So, just mocking UPD: I think that tests running in parallel are not a problem however. Probably currently we don't have tests that may fail because of the advancing system time. And as for new tests on message timestamps, they just must assume that the system time can jump forth, so there must be more careful timestamp checks but otherwise this looks like a working solution. |
Maybe it is a reference to |
I've already done with mocking Btw, with this |
8ed0d33
to
9863cdb
Compare
9863cdb
to
3b8609c
Compare
3b8609c
to
3016600
Compare
8c595e3
to
7892034
Compare
If a time value doesn't need to be sent to another host, saved to the db or otherwise used across program restarts, a monotonically nondecreasing clock (`Instant`) should be used. But as `Instant` may use `libc::clock_gettime(CLOCK_MONOTONIC)`, e.g. on Android, and does not advance while being in deep sleep mode, get rid of `Instant` in favor of using `SystemTime`, but add `tools::Time` as an alias for it with the appropriate comment so that it's clear why `Instant` isn't used in those places and to protect from unwanted usages of `Instant` in the future. Also this can help to switch to another clock impl if we find any.
… in a row The system clock may be adjusted and even go back, so caching system time in code sections where it's not supposed to change may even protect from races/bugs.
7892034
to
9f4baaf
Compare
See commit messages.