~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Tests for Knit data structure"""
18
18
 
19
19
from cStringIO import StringIO
 
20
import gzip
20
21
import sys
21
22
 
22
23
from bzrlib import (
27
28
    pack,
28
29
    tests,
29
30
    transport,
30
 
    tuned_gzip,
31
31
    )
32
32
from bzrlib.errors import (
33
33
    KnitHeaderError,
338
338
        writer.end()
339
339
        return memos
340
340
 
 
341
    def test_pack_collection_pack_retries(self):
 
342
        """An explicit pack of a pack collection succeeds even when a
 
343
        concurrent pack happens.
 
344
        """
 
345
        builder = self.make_branch_builder('.')
 
346
        builder.start_series()
 
347
        builder.build_snapshot('rev-1', None, [
 
348
            ('add', ('', 'root-id', 'directory', None)),
 
349
            ('add', ('file', 'file-id', 'file', 'content\nrev 1\n')),
 
350
            ])
 
351
        builder.build_snapshot('rev-2', ['rev-1'], [
 
352
            ('modify', ('file-id', 'content\nrev 2\n')),
 
353
            ])
 
354
        builder.build_snapshot('rev-3', ['rev-2'], [
 
355
            ('modify', ('file-id', 'content\nrev 3\n')),
 
356
            ])
 
357
        self.addCleanup(builder.finish_series)
 
358
        b = builder.get_branch()
 
359
        self.addCleanup(b.lock_write().unlock)
 
360
        repo = b.repository
 
361
        collection = repo._pack_collection
 
362
        # Concurrently repack the repo.
 
363
        reopened_repo = repo.bzrdir.open_repository()
 
364
        reopened_repo.pack()
 
365
        # Pack the new pack.
 
366
        collection.pack()
 
367
 
341
368
    def make_vf_for_retrying(self):
342
369
        """Create 3 packs and a reload function.
343
370
 
692
719
 
693
720
    def create_gz_content(self, text):
694
721
        sio = StringIO()
695
 
        gz_file = tuned_gzip.GzipFile(mode='wb', fileobj=sio)
 
722
        gz_file = gzip.GzipFile(mode='wb', fileobj=sio)
696
723
        gz_file.write(text)
697
724
        gz_file.close()
698
725
        return sio.getvalue()