~dobey/ubuntuone-client/fix-test-fails

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_sync.py

Tests for chunked rescan from scratch with changes in the middle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1631
1631
        self.main.fs.set_by_mdid(node.mdid, generation=dt.generation)
1632
1632
        return node
1633
1633
 
1634
 
    def create_dir(self):
 
1634
    def create_dir(self, dt=None):
1635
1635
        """Create a directory based on self.dirdelta."""
1636
 
        dt = self.dirdelta
 
1636
        if dt is None:
 
1637
            dt = self.dirdelta
1637
1638
        mdobj = self.main.fs.get_by_node_id(dt.share_id, dt.parent_id)
1638
1639
        path = os.path.join(
1639
1640
            self.main.fs.get_abspath(dt.share_id, mdobj.path),
2090
2091
            (ROOT, self.dirdelta.node_id, True)])
2091
2092
 
2092
2093
 
 
2094
class TestChunkedRescanFromScratchOk(TestHandleAqRescanFromScratchOk):
 
2095
 
 
2096
    def test_change_in_the_middle(self):
 
2097
        """Chunked delta handling with a change in the middle."""
 
2098
        directories = [self.rootdt]
 
2099
        files = []
 
2100
        for i in range(1,5):
 
2101
            d = delta.FileInfoDelta(
 
2102
                generation=i, is_live=True, file_type=delta.DIRECTORY,
 
2103
                parent_id=self.root_id, share_id=ROOT, node_id=uuid.uuid4(),
 
2104
                name=u"directory_ñ_%d" % i, is_public=False,
 
2105
                content_hash="hash", crc32=i, size=10, last_modified=0)
 
2106
            directories.append(d)
 
2107
            self.create_dir(dt=d)
 
2108
        for i in range(6, 10):
 
2109
            f = delta.FileInfoDelta(
 
2110
                generation=i, is_live=True, file_type=delta.FILE,
 
2111
                parent_id=self.root_id, share_id=ROOT, node_id=uuid.uuid4(),
 
2112
                name=u"fileñ.%d.txt" % i, is_public=False, content_hash="hash",
 
2113
                crc32=i, size=10, last_modified=0)
 
2114
            f.parent_id = directories[i-5].node_id
 
2115
            self.create_filetxt(dt=f)
 
2116
            files.append(f)
 
2117
 
 
2118
        called = []
 
2119
        orig__handle_SV_FILE_DELETED = self.sync._handle_SV_FILE_DELETED
 
2120
        self.sync._handle_SV_FILE_DELETED = \
 
2121
                self.sync._handle_SV_FILE_DELETED = \
 
2122
                lambda *args: called.append(args)
 
2123
 
 
2124
        # build a delta with files[3] node missing, caused by a change by other
 
2125
        # client while building the delta
 
2126
        fake_delta = directories + files[0:2] + files[3:5]
 
2127
        self.sync.handle_AQ_RESCAN_FROM_SCRATCH_OK(ROOT,
 
2128
            fake_delta, files[-1].generation, 100)
 
2129
 
 
2130
        self.assertEqual(called, [
 
2131
            (ROOT, files[2].node_id, False)])
 
2132
 
 
2133
        # call the real delete method.
 
2134
        orig__handle_SV_FILE_DELETED(*called[0])
 
2135
 
 
2136
        # now fake the get_delta for the changed node that was missing in the
 
2137
        # rescan_from_scratch
 
2138
        changed_file = files[2]
 
2139
        changed_file.generation = files[-1].generation+1
 
2140
        changed_file.hash = "hash-1"
 
2141
 
 
2142
        called = []
 
2143
        self.sync._handle_SV_FILE_DELETED = \
 
2144
            lambda *args: called.append(("delete",)+args)
 
2145
        self.sync._handle_SV_MOVED = \
 
2146
            lambda *args: called.append(("move",)+args)
 
2147
        self.sync._handle_SV_HASH_NEW = \
 
2148
            lambda *args: called.append(("new_hash",)+args)
 
2149
        self.sync._handle_SV_FILE_NEW = \
 
2150
            lambda *args: called.append(("new_file",)+args)
 
2151
        self.sync._handle_SV_DIR_NEW = \
 
2152
            lambda *args: called.append(("new_dir",)+args)
 
2153
 
 
2154
        self.sync.handle_AQ_DELTA_OK(ROOT,
 
2155
            [changed_file], changed_file.generation, True, 100)
 
2156
        self.assertEqual(called, [
 
2157
            ("new_file", ROOT, changed_file.node_id, changed_file.parent_id,
 
2158
             changed_file.name.encode("utf-8"))])
 
2159
 
 
2160
    def test_move_in_the_middle(self):
 
2161
        """Chunked delta handling with a move in the middle."""
 
2162
        directories = [self.rootdt]
 
2163
        files = []
 
2164
        for i in range(1,5):
 
2165
            d = delta.FileInfoDelta(
 
2166
                generation=i, is_live=True, file_type=delta.DIRECTORY,
 
2167
                parent_id=self.root_id, share_id=ROOT, node_id=uuid.uuid4(),
 
2168
                name=u"directory_ñ_%d" % i, is_public=False,
 
2169
                content_hash="hash", crc32=i, size=10, last_modified=0)
 
2170
            directories.append(d)
 
2171
            self.create_dir(dt=d)
 
2172
        for i in range(6, 10):
 
2173
            f = delta.FileInfoDelta(
 
2174
                generation=i, is_live=True, file_type=delta.FILE,
 
2175
                parent_id=self.root_id, share_id=ROOT, node_id=uuid.uuid4(),
 
2176
                name=u"fileñ.%d.txt" % i, is_public=False, content_hash="hash",
 
2177
                crc32=i, size=10, last_modified=0)
 
2178
            f.parent_id = directories[i-5].node_id
 
2179
            self.create_filetxt(dt=f)
 
2180
            files.append(f)
 
2181
 
 
2182
        called = []
 
2183
        orig__handle_SV_FILE_DELETED = self.sync._handle_SV_FILE_DELETED
 
2184
        self.sync._handle_SV_FILE_DELETED = \
 
2185
                self.sync._handle_SV_FILE_DELETED = \
 
2186
                lambda *args: called.append(args)
 
2187
 
 
2188
        # build a delta with files[3] node missing, caused by a change by other
 
2189
        # client while building the delta
 
2190
        fake_delta = directories + files[0:2] + files[3:5]
 
2191
        self.sync.handle_AQ_RESCAN_FROM_SCRATCH_OK(ROOT,
 
2192
            fake_delta, files[-1].generation, 100)
 
2193
 
 
2194
        self.assertEqual(called, [
 
2195
            (ROOT, files[2].node_id, False)])
 
2196
 
 
2197
        # call the real delete method.
 
2198
        orig__handle_SV_FILE_DELETED(*called[0])
 
2199
 
 
2200
        # now fake the get_delta for the moved node that was missing in the
 
2201
        # rescan_from_scratch
 
2202
        changed_file = files[2]
 
2203
        changed_file.generation = files[-1].generation+1
 
2204
        changed_file.parent_id = directories[1].node_id
 
2205
 
 
2206
        called = []
 
2207
        self.sync._handle_SV_FILE_DELETED = \
 
2208
            lambda *args: called.append(("delete",)+args)
 
2209
        self.sync._handle_SV_MOVED = \
 
2210
            lambda *args: called.append(("move",)+args)
 
2211
        self.sync._handle_SV_HASH_NEW = \
 
2212
            lambda *args: called.append(("new_hash",)+args)
 
2213
        self.sync._handle_SV_FILE_NEW = \
 
2214
            lambda *args: called.append(("new_file",)+args)
 
2215
        self.sync._handle_SV_DIR_NEW = \
 
2216
            lambda *args: called.append(("new_dir",)+args)
 
2217
 
 
2218
        self.sync.handle_AQ_DELTA_OK(ROOT,
 
2219
            [changed_file], changed_file.generation, True, 100)
 
2220
        self.assertEqual(called, [
 
2221
            ("new_file", ROOT, changed_file.node_id, changed_file.parent_id,
 
2222
             changed_file.name.encode("utf-8"))])
 
2223
 
 
2224
 
2093
2225
class TestSyncEvents(TestSyncDelta):
2094
2226
    """Testing sync stuff related to events."""
2095
2227