/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-05-11 15:26:20 UTC
  • mto: (5743.12.1 config-options)
  • mto: This revision was merged to the branch mainline in revision 5941.
  • Revision ID: v.ladeuil+lp@free.fr-20110511152620-6ue3yhx205lle108
One more test with a ugly hack to allow the test to stop in the right place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2163
2163
        c1.set('two', 'done')
2164
2164
        self.assertEquals('c2', c1.get('one'))
2165
2165
 
 
2166
    def test_writes_are_serialized(self):
 
2167
        c1 = self.stack
 
2168
        c2 = self.get_stack(self)
 
2169
 
 
2170
        # We spawn a thread that will pause *during* the write
 
2171
        before_writing = threading.Event()
 
2172
        after_writing = threading.Event()
 
2173
        writing_done = threading.Event()
 
2174
        c1_save_orig = c1.store._save
 
2175
        def c1_save():
 
2176
            before_writing.set()
 
2177
            c1_save_orig()
 
2178
            # The lock is held. We wait for the main thread to decide when to
 
2179
            # continue
 
2180
            after_writing.wait()
 
2181
        c1.store._save = c1_save
 
2182
        def c1_set():
 
2183
            c1.set('one', 'c1')
 
2184
            writing_done.set()
 
2185
        t1 = threading.Thread(target=c1_set)
 
2186
        # Collect the thread after the test
 
2187
        self.addCleanup(t1.join)
 
2188
        # Be ready to unblock the thread if the test goes wrong
 
2189
        self.addCleanup(after_writing.set)
 
2190
        t1.start()
 
2191
        before_writing.wait()
 
2192
        self.assertTrue(c1.store._lock.is_held)
 
2193
        self.assertRaises(errors.LockContention,
 
2194
                          c2.set, 'one', 'c2')
 
2195
        self.assertEquals('c1', c1.get('one'))
 
2196
        # Let the lock be released
 
2197
        after_writing.set()
 
2198
        writing_done.wait()
 
2199
        c2.set('one', 'c2')
 
2200
        self.assertEquals('c2', c2.get('one'))
 
2201
 
2166
2202
    # FIXME: We should adapt the tests in TestLockableConfig about concurrent
2167
2203
    # writes. Since this requires a clearer rewrite, I'll just rely on using
2168
2204
    # the same code in LockableIniFileStore (copied from LockableConfig, but