feat: Mock SystemTime::now() for the tests#5113
Merged
Conversation
link2xt
reviewed
Dec 18, 2023
link2xt
reviewed
Dec 18, 2023
9863cdb to
3b8609c
Compare
474f832 to
b1d1267
Compare
Hocuri
approved these changes
Jan 19, 2024
Collaborator
Hocuri
left a comment
There was a problem hiding this comment.
LGTM - two minor comments
b1d1267 to
2639b5c
Compare
3b8609c to
3016600
Compare
2639b5c to
3f992f7
Compare
Collaborator
Author
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
Collaborator
Author
|
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
link2xt
approved these changes
Feb 15, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See commit messages