Compare commits

...
Author SHA1 Message Date
Alexandre Teixeira 958848f9f8 test: interleave concurrent IMAP deletion before expunge 2026-10-29 01:51:41 +00:00
+21 -4
View File
@@ -315,15 +315,32 @@ def test_server_lacking_uidplus_never_calls_mailbox_expunge(bulk_delete):
bulk_delete.index_delete.assert_not_called() bulk_delete.index_delete.assert_not_called()
def test_concurrent_client_marks_unrelated_deleted_message_during_operation(bulk_delete): def test_concurrent_client_marks_unrelated_deleted_message_during_operation(bulk_delete, monkeypatch):
# Another client marks unrelated UID 999 \Deleted before/during the operation mailbox = bulk_delete.mailbox
bulk_delete.mailbox.inbox.add("999") mailbox.inbox.add("999")
bulk_delete.mailbox.deleted.add("999") assert "999" not in mailbox.deleted
uid_command = mailbox.uid
interleavings = []
def other_client_marks_deleted(command, uid, *args):
response = uid_command(command, uid, *args)
if command == "STORE" and uid == b"101" and args[0] == "+FLAGS":
# The requested message is flagged; another client now flags 999
# before the server receives the subsequent EXPUNGE command.
assert mailbox.deleted == {"101"}
assert not any(cmd == "EXPUNGE" for cmd, _ in mailbox.calls)
mailbox.deleted.add("999")
interleavings.append("STORE")
return response
monkeypatch.setattr(mailbox, "uid", other_client_marks_deleted)
result = bulk_delete.delete(["101"]) result = bulk_delete.delete(["101"])
assert result["success"] is True assert result["success"] is True
assert result["deleted_uids"] == ["101"] assert result["deleted_uids"] == ["101"]
assert interleavings == ["STORE"]
assert mailbox.inbox == {"102", "103", "999"}
# 101 was expunged, unrelated 999 is NEVER expunged # 101 was expunged, unrelated 999 is NEVER expunged
assert "101" not in bulk_delete.mailbox.inbox assert "101" not in bulk_delete.mailbox.inbox
assert "999" in bulk_delete.mailbox.inbox assert "999" in bulk_delete.mailbox.inbox