def test_get_all_nodes_chunked_with_changes(self):
        """Test chunked get_all_nodes with changes in the middle."""
        share_dao = SharedDirectory(self.rw_share, by_user=self.sharer)
        sgw = ReadWriteVolumeGateway(self.user, share=share_dao)
        root = sgw.get_root()
        root_id = root.id
        # make dirs and put files in them
        dirs = []
        files = []
        for i in range(10):
            d = sgw.make_subdirectory(root_id, '%sd' % i)
            f = sgw.make_file(d.id, '%sfile.txt' % i)
            dirs.append(d)
            files.append(f)
        all_nodes = dirs + files
        all_nodes.append(root)
        # sort them in the right order
        all_nodes.sort(key=attrgetter('path', 'name'))
        # filter nodes until gen 19
        nodes = [n for n in all_nodes if n.generation <= 19]
        nodes_gen_19 = sgw.get_all_nodes(max_generation=19)

        self.assertEqual(nodes_gen_19, nodes)

        # same but with the last generation
        nodes_limit_5 = sgw.get_all_nodes(max_generation=19, limit=5)
        self.assertEqual(nodes_limit_5, nodes[:5])

        # now make some changes,
        # create a new dir.
        new_dir = sgw.make_subdirectory(root_id, '01d')

        last_node = nodes_limit_5[-1]
        nodes_limit_5 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=19, limit=5)

        self.assertEqual(nodes_limit_5, nodes[:10])

        # create a new file inside a existing dir.
        sgw.make_file(nodes[5].id, '0_new_file.txt')

        last_node = nodes_limit_5[-1]
        nodes_limit_5 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=19, limit=5)
        self.assertEqual(nodes_limit_5, nodes[:15])

        # and also make a move
        to_move = nodes[10:15][2]
        sgw.move_node(to_move.id, new_dir.id, to_move.name)
        last_node = nodes_limit_5[-1]
        # get the rest of the result.
        nodes_limit_5 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=19)
        self.assertEqual(nodes_limit_5, nodes_gen_19)

        # now move a node that should have been in the result,
        # but before getting to it.
        to_move = nodes_gen_19[-1]
        sgw.move_node(to_move.id, nodes_gen_19[0].id, to_move.name)
        last_node = nodes_gen_19[-5]
        result = sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=19)
        # check that it wasn't included in the result.
        self.assertEqual(result, nodes_gen_19[-4:-1])