-
-
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
feat: Mock SystemTime::now() for the tests #5113
Conversation
9863cdb
to
3b8609c
Compare
474f832
to
b1d1267
Compare
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.
LGTM - two minor comments
b1d1267
to
2639b5c
Compare
3b8609c
to
3016600
Compare
2639b5c
to
3f992f7
Compare
Thanks for reviewing, but finally i think it indeed should be moved to a separate crate, even as is, maybe it will be useful elsewhere. I think that #5108 should be merged first at least to avoid text conflicts. |
3f992f7
to
969900c
Compare
So, now this fake struct is |
3016600
to
8c595e3
Compare
969900c
to
c45fbd0
Compare
8c595e3
to
7892034
Compare
c45fbd0
to
35d733a
Compare
7892034
to
9f4baaf
Compare
35d733a
to
34a3fd5
Compare
Add a new crate `deltachat_time` with a fake `struct SystemTimeTools` for mocking `SystemTime::now()` for test purposes. One still needs to use `std::time::SystemTime` as a struct representing a system time. I think such a minimalistic approach is ok -- even if somebody uses the original `SystemTime::now()` instead of the mock by mistake, that could break only tests but not the program itself. The worst thing that can happen is that tests using `SystemTime::shift()` and checking messages timestamps f.e. wouldn't catch the corresponding bugs, but now we don't have such tests at all which is much worse.
Even if `vc-request-with-auth` is received with a delay, the protection message must have the sort timestamp equal to the Sent timestamp of `vc-request-with-auth`, otherwise subsequent chat messages would also have greater sort timestamps and while it doesn't affect the chat itself (because Sent timestamps are shown to a user), it affects the chat position in the chatlist because chats there are sorted by sort timestamps of the last messages, so the user sees chats sorted out of order. That's what happened in #5088 where a user restores the backup made before setting up a verified chat with their contact and fetches new messages, including `vc-request-with-auth` and also messages from other chats, after that.
34a3fd5
to
38a6c8c
Compare
See commit messages