Skip to content

Commit

Permalink
fix test_cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
LipuFei committed Sep 10, 2014
1 parent 131c366 commit 9d0f83b
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions tests/test_cancel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from unittest import skip

from .dispersytestclass import DispersyTestFunc
from ..util import blocking_call_on_reactor_thread

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -136,17 +136,16 @@ def fetch_all_messages():
self._logger.debug("_______ %s", row)
other.call(fetch_all_messages)

self._logger.debug("%d", len(low_message.packet))
self._logger.debug("%d", len(high_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):
"""
Expand All @@ -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)
Expand All @@ -187,8 +186,8 @@ 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.
"""
node, other = self.create_nodes(2)
node.send_identity(other)
Expand All @@ -207,11 +206,11 @@ 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
revoke = self._mm.create_revoke([(node.my_member, self._community.get_meta_message(u"full-sync-text"),
u"cancel")])
other.give_message(revoke, self._mm)
other.assert_is_canceled(message)
other.assert_is_canceled(message, canceled_by=cancel)

0 comments on commit 9d0f83b

Please sign in to comment.