fix: Make pre-messages w/o text want MDNs (#8004)#8008
Conversation
4fdd476 to
9afce7d
Compare
|
I made a bug in the test -- bob doesn't accept the chat -- and this looks suspicious to me: Why is bob's self-MDN being processed after the decryption failure? It should go to the trash just because of that and no message should be tried to be added. |
9afce7d to
d3370d5
Compare
|
|
||
| pub async fn pop_sent_msg_opt(&self, timeout: Duration) -> Option<SentMessage<'_>> { | ||
| let from_head = self | ||
| .get_config_bool(Config::PopSentMsgFromHead) |
There was a problem hiding this comment.
Can we instead have a new function shift_sent_msg_opt that does this and not a global config that is only used for tests? Otherwise we will have to add this config to all tests over time.
There was a problem hiding this comment.
Otherwise we will have to add this config to all tests over time.
Why? Only to those where sending messages from head is needed to reproduce some regression. Anyway, do you mean adding a function that moves an smtp job from head to tail?
There was a problem hiding this comment.
I mean creating a function shift_sent_msg_opt that takes message from the beginning of the queue rather than the end, so we can use it in new tests.
There was a problem hiding this comment.
The first i wanted to do is to create unqueue_sent_msg_opt() which does the same as pop_sent_msg_opt(), but takes the first queued message. But there are other functions calling pop_sent_msg_opt(), so we should forward some flag everywhere. E.g. in the new test it's send_msg() returning SentMessage. Note sure you mean the same, what does shift_ mean? Anyway, i'd avoid adding a flag everywhere, better we add a new Config key or some flag (maybe one-shot) to Context.
I also don't expect many tests needing this, so a config key doesn't look like a problem.
There was a problem hiding this comment.
Also it appeared that not the sending order is a problem, but absence of message text, so i can drop this part at all. But as it's already done, maybe let it remain?
EDIT: The discussion here is a bit outdated because pop_sent_msg_ex() was added meanwhile, but we still need a way to revert the order for messages popped from the SMTP queue indirectly.
There was a problem hiding this comment.
Removed this Config::PopSentMsgFromHead, chat::send_msg() can be used in tests directly, which doesn't pop any message from smtp, then sent messages can be popped by calling TestContext::pop_sent_msg_ex() which pops from head by default.
d3370d5 to
d2f33f5
Compare
40058de to
7d5c3f3
Compare
7d5c3f3 to
c70705d
Compare
c70705d to
d3c0bb0
Compare
d3c0bb0 to
77edcea
Compare
| SendResult::Success => { | ||
| if !recipients.is_empty() { | ||
| info!(context, "Successfully sent MDN for {rfc724_mid}."); | ||
| #[cfg(not(test))] |
There was a problem hiding this comment.
I really don't like conditional compilation and generally changing the code just for a single test, like adding hooks, options and code paths that are only needed to make the tests pass. If every test adds this, we will end up with unmaintainable code because every time a change to such function is needed someone will have to make sure that the code added for the test does not break as well.
If the function is too large to be usable in a test, e.g. because it makes SMTP connections, it can be refactored first into smaller functions to make it possible to call relevant parts from the test.
There was a problem hiding this comment.
I added a commit removing conditional compilation by passing different callbacks for MDN sending from the release and test code. Not sure this resolves your comment however, but the idea isn't that every test adds a new conditional compilation block or a new callback, but all tests pass the same callback to send_mdn() so that we only have two: the real and the test ("mock") ones. We anyway cannot test in Rust the same code that we really run.
At least now, with callbacks instead of conditional compilation, code isolation is better, e.g. the test code can't be affected by local vars.
There was a problem hiding this comment.
One more way to refactor this is to add another set of smtp functions (namely, send_mdn_rfc724_mid() and send_mdn()) for tests and extract common code blocks into separate functions shared with the release code, but i afraid this will worsen readability and it'll be even difficult to name those common functions meaningfully.
There was a problem hiding this comment.
Have made send_fn impl AsyncFnOnce and removed extra parameters from it, they are now bound to closures.
@link2xt is this callback approach enough? I'm not sure that breaking everything into smaller functions will improve maintainability
98d91da to
94a895f
Compare
94a895f to
e15b366
Compare
e15b366 to
136b6e4
Compare
136b6e4 to
9b7e7f0
Compare
9b7e7f0 to
e88940e
Compare
e88940e to
886d6c4
Compare
| .await?, | ||
| 1 | ||
| ); | ||
| smtp::queue_mdn(bob).await; |
There was a problem hiding this comment.
To avoid complicating send_mdn_rfc724_mid with hooks and test code: it is enough to check that the message WantsMdn and smtp_mdns has an entry, as already checked above.
It indeed looks bad that send_mdn_rfc724_mid does SMTP sending itself rather than just queueing a message and interrupting SMTP loop and probably should be refactored, but it's better not to do any refactoring of this function in this PR.
There was a problem hiding this comment.
Is it actually that bad (less readable?) that send_mdn_rfc724_mid() now accepts send_fn instead of smtp: &mut Smtp? It's not a test hook like we had before and have already removed. Rather a way to abstract parts of the code.
In this test it's ok to just check for presence of the smtp_mdns entry because it tests a sender-side bug. But what to do in tests actually needing to receive MDNs we send, like e.g. 67a75a4? If we never refactor this MDN sending pipeline, the only way to test receiving MDNs is to put them into test-data/ which is really harder to maintain. Testing receiving Detlta Chat -generated MDNs in Python tests isn't always helpful because of timings. Sometimes an MDN needs to be received at an exact moment.
...
It indeed looks bad that
send_mdn_rfc724_middoes SMTP sending itself rather than just queueing a message and interrupting SMTP loop and probably should be refactored, but it's better not to do any refactoring of this function in this PR.
Agree, that would be a quite big refactoring for this PR. In the current state the PR only moves a part of the code into AsyncFnOnce(&str, String, Vec<String>) -> Result<bool>, this is all the refactoring.
…ssage state to OutMdnRcvd (#8004)
886d6c4 to
9d6c7e5
Compare
9d6c7e5 to
42cda75
Compare
This fixes failing `test_pre_msg_mdn_before_sending_full`. Maybe it's even good that MDNs will be sent for pre-messages only having placeholder text with the viewtype and size, at least this way we notify the contact that we've noticed the message. Anyway, with adding message previews the problem will be solved for the corresponding viewtypes.
42cda75 to
76f6919
Compare
This fixes #8004 . Maybe it's even good that MDNs will
be sent for pre-messages only having placeholder text with the viewtype and size, at least this way
we notify the contact that we've noticed the message. Anyway, with adding message previews the
problem will be solved for the corresponding viewtypes.