'Test the on_tunnel_remove handler function for a circuit'

@blocking_call_on_reactor_thread
@inlineCallbacks
def test_on_tunnel_remove(self):

    (node, other) = (yield self.create_nodes(2))
    tunnel_node = Circuit(long(0), 0)
    tunnel_other = Circuit(long(0), 0)
    tunnel_node.bytes_up = tunnel_other.bytes_down = ((12 * 1024) * 1024)
    tunnel_node.bytes_down = tunnel_other.bytes_up = ((14 * 1024) * 1024)
    node.call(node.community.on_tunnel_remove, None, None, tunnel_node, self._create_target(node, other))
    other.call(other.community.on_tunnel_remove, None, None, tunnel_other, self._create_target(other, node))
    (yield deferLater(reactor, 5.1, (lambda : None)))
    (_, signature_request) = node.receive_message(names=[HALF_BLOCK]).next()
    node.give_message(signature_request, other)
    (yield deferLater(reactor, 0.1, (lambda : None)))
    (_, signature_request) = other.receive_message(names=[HALF_BLOCK]).next()
    other.give_message(signature_request, node)
    (yield deferLater(reactor, 0.1, (lambda : None)))
    self.assertBlocksInDatabase(node, 2)
    self.assertBlocksInDatabase(other, 2)
    self.assertBlocksAreEqual(node, other)
