'Test the on_tunnel_remove handler function for a circuit'

@blocking_call_on_reactor_thread
@inlineCallbacks
def test_on_tunnel_remove_small(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 = 1024
    tunnel_node.bytes_down = tunnel_other.bytes_up = (2 * 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)))
    with self.assertRaises(StopIteration):
        self.assertFalse(node.receive_message(names=[HALF_BLOCK]).next())
    with self.assertRaises(StopIteration):
        self.assertFalse(other.receive_message(names=[HALF_BLOCK]).next())
    self.assertBlocksInDatabase(node, 0)
    self.assertBlocksInDatabase(other, 0)
