72
73
config.test_store_builder_registry.register(
73
74
'location', lambda test: config.LocationStore())
77
def build_backing_branch(test, relpath,
78
transport_class=None, server_class=None):
79
"""Test helper to create a backing branch only once.
81
Some tests needs multiple stores/stacks to check concurrent update
82
behaviours. As such, they need to build different branch *objects* even if
83
they share the branch on disk.
85
:param relpath: The relative path to the branch. (Note that the helper
86
should always specify the same relpath).
88
:param transport_class: The Transport class the test needs to use.
90
:param server_class: The server associated with the ``transport_class``
93
Either both or neither of ``transport_class`` and ``server_class`` should
96
if transport_class is not None and server_class is not None:
97
test.transport_class = transport_class
98
test.transport_server = server_class
99
elif not (transport_class is None and server_class is None):
100
raise AssertionError('Specify both ``transport_class`` and '
101
'``server_class`` or neither of them')
102
if getattr(test, 'backing_branch', None) is None:
103
# First call, let's build the branch on disk
104
test.backing_branch = test.make_branch(relpath)
107
def keep_branch_alive(test, b):
108
"""Keep a branch alive for the duration of a test.
110
:param tests: the test that should hold the branch alive.
112
:param b: the branch that should be kept alive.
114
Several tests need to keep a reference to a branch object as they are
115
testing a Store which uses a weak reference. This is achieved by embedding
116
a reference to the branch object in a lambda passed to a cleanup. When the
117
test finish the cleanup method is deleted and so does the reference to the
120
test.addCleanup(lambda : b)
75
123
def build_branch_store(test):
76
if getattr(test, 'branch', None) is None:
77
test.branch = test.make_branch('branch')
78
# Since we can be called to create different stores, we need to build them
79
# from different branch *objects*, even if they point to the same branch on
80
# disk, otherwise tests about conccurent updates won't be able to trigger
82
return config.BranchStore(branch.Branch.open('branch'))
124
build_backing_branch(test, 'branch')
125
b = branch.Branch.open('branch')
126
keep_branch_alive(test, b)
127
return config.BranchStore(b)
83
128
config.test_store_builder_registry.register('branch', build_branch_store)
131
def build_remote_branch_store(test):
132
# There is only one permutation (but we won't be able to handle more with
133
# this design anyway)
134
(transport_class, server_class) = remote.get_test_permutations()[0]
135
build_backing_branch(test, 'branch', transport_class, server_class)
136
b = branch.Branch.open(test.get_url('branch'))
137
keep_branch_alive(test, b)
138
return config.BranchStore(b)
139
config.test_store_builder_registry.register('remote_branch',
140
build_remote_branch_store)
86
143
config.test_stack_builder_registry.register(
87
144
'bazaar', lambda test: config.GlobalStack())
88
145
config.test_stack_builder_registry.register(
89
146
'location', lambda test: config.LocationStack('.'))
91
149
def build_branch_stack(test):
92
if getattr(test, 'branch', None) is None:
93
test.branch = test.make_branch('branch')
94
# Since we can be called to create different stacks, we need to build them
95
# from different branch *objects*, even if they point to the same branch on
96
# disk, otherwise tests about conccurent updates won't be able to trigger
98
return config.BranchStack(branch.Branch.open('branch'))
150
build_backing_branch(test, 'branch')
151
b = branch.Branch.open('branch')
152
keep_branch_alive(test, b)
153
return config.BranchStack(b)
99
154
config.test_stack_builder_registry.register('branch', build_branch_stack)
157
def build_remote_branch_stack(test):
158
# There is only one permutation (but we won't be able to handle more with
159
# this design anyway)
160
(transport_class, server_class) = remote.get_test_permutations()[0]
161
build_backing_branch(test, 'branch', transport_class, server_class)
162
b = branch.Branch.open(test.get_url('branch'))
163
keep_branch_alive(test, b)
164
return config.BranchStack(b)
165
config.test_stack_builder_registry.register('remote_branch',
166
build_remote_branch_stack)
102
169
sample_long_alias="log -r-15..-1 --line"
103
170
sample_config_text = u"""
2114
2184
self.assertPathExists('dir/subdir')
2187
class TestBranchStore(TestStore):
2189
def test_dead_branch(self):
2190
build_backing_branch(self, 'branch')
2191
b = branch.Branch.open('branch')
2192
store = config.BranchStore(b)
2194
# The only reliable way to trigger the error is to explicitly call the
2195
# garbage collector.
2198
store.get_mutable_section(None).set('foo', 'bar')
2199
self.assertRaises(AssertionError, store.save)
2117
2202
class TestConcurrentStoreUpdates(TestStore):
2203
"""Test that Stores properly handle conccurent updates.
2205
New Store implementation may fail some of these tests but until such
2206
implementations exist it's hard to properly filter them from the scenarios
2207
applied here. If you encounter such a case, contact the bzr devs.
2119
2210
scenarios = [(key, {'get_stack': builder}) for key, builder
2120
2211
in config.test_stack_builder_registry.iteritems()]