diff --git a/tests/test_cancel.py b/tests/test_cancel.py index 233cc26f..4b6e8112 100644 --- a/tests/test_cancel.py +++ b/tests/test_cancel.py @@ -1,5 +1,3 @@ -from unittest import skip - from .dispersytestclass import DispersyTestFunc from ..util import blocking_call_on_reactor_thread @@ -80,17 +78,22 @@ def create_cancel(): cancel1 = node.call(create_cancel) self.assertIsNotNone(cancel1.packet) + self._logger.debug(u"!!!! second time") self.assertRaises(RuntimeError, create_cancel) - @skip("Will change this test to a meaningful one") def test_node_resolve_cancel_twice(self): """ - Make sure that in the event of receiving two cancel messages from the same member, both will be stored, - and in case of receiving a lower one, that we will send the higher one back to the sender. + If we receive two cancel messages canceling the same message, the higher one should be stored as the + latest cancel messages. + + The latest cancel message is the one that has the highest (global_time, mid) combination. - MM gives NODE permission to cancel, NODE generates a message and then cancels it twice. - Both messages should be kept and the lowest one should be canceled. + In this test, we first same the original message C0, then we send the higher cancel message C2, + and finally the lower cancel message C1. + The receiver first updates its database with C2 as the latest cancel message of C0. + When it receives C1, it will recognise that it has C2 > C1, and it sends C2 to the sender + to inform him with the latest cancel message of C0. """ node, other = self.create_nodes(2) node.send_identity(other) @@ -108,12 +111,9 @@ def test_node_resolve_cancel_twice(self): cancel1 = node.create_cancel_own(message, 11) cancel2 = node.create_cancel_own(message, 12) low_message, high_message = sorted([cancel1, cancel2], key=lambda msg: msg.packet) - self._logger.debug("!!! give message") other.give_message(message, node) - self._logger.debug("!!! give low_message") - other.give_message(low_message, node) - self._logger.debug("!!! give high_message") other.give_message(high_message, node) + other.give_message(low_message, node) # OTHER should send the first message back when receiving # the second one (its "higher" than the one just received) cancel_packets = list() @@ -138,15 +138,14 @@ def fetch_all_messages(): self._logger.debug("%d", len(low_message.packet)) - self.assertEqual(len(cancel_packets), len([low_message.packet])) + self.assertEqual(len(cancel_packets), len([high_message.packet])) # NODE should have both messages on the database and the lowest one should be undone by the highest. messages = other.fetch_messages((u"dispersy-cancel-own",)) self.assertEquals(len(messages), 2) - other.assert_is_done(low_message) - other.assert_is_canceled(high_message) - other.assert_is_canceled(high_message, canceled_by=low_message) - other.assert_is_canceled(message, canceled_by=low_message) + other.assert_is_stored(low_message) + other.assert_is_stored(high_message) + other.assert_is_canceled(message, canceled_by=high_message) def test_missing_message(self): """ @@ -170,7 +169,7 @@ def test_missing_message(self): # receive the dispersy-missing-message messages global_times = [message.distribution.global_time for message in messages] - global_time_requests = [] + global_time_requests = list() for _, message in node.receive_messages(names=[u"dispersy-missing-message"]): self.assertEqual(message.payload.member.public_key, node.my_member.public_key) @@ -187,8 +186,10 @@ def test_missing_message(self): def test_revoke_causing_cancel(self): """ - SELF gives NODE permission to cancel, OTHER created a message, NODE cancels the message, SELF - revokes the cancel permission AFTER the message was canceled -> the message is not re-done. + SELF gives NODE permission to cancel, OTHER created a message M1, NODE cancels the message with C1, SELF + revokes the cancel permission AFTER the message was canceled -> the message is not resumed. + After that, NODE creates another cancel message C2 and sends it to OTHER, OTHER will have C2 + stored but the original message M1 will has C1 as its latest cancel message. """ node, other = self.create_nodes(2) node.send_identity(other) @@ -207,7 +208,7 @@ def test_revoke_causing_cancel(self): # NODE cancels the message cancel = node.create_cancel_other(message, message.distribution.global_time + 1) other.give_message(cancel, node) - other.assert_is_canceled(message) + other.assert_is_canceled(message, canceled_by=cancel) other.assert_is_stored(cancel) # SELF revoke cancel permission from NODE @@ -215,3 +216,9 @@ def test_revoke_causing_cancel(self): u"cancel")]) other.give_message(revoke, self._mm) other.assert_is_canceled(message) + + # NODE make another cancel message and send it to OTHER + cancel2 = node.create_cancel_other(message, message.distribution.global_time + 2) + other.give_message(cancel2, node) + other.assert_is_canceled(message, canceled_by=cancel) + other.assert_is_stored(cancel2)