~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/tests/test_rewrite.py

  • Committer: Stuart Bishop
  • Date: 2011-08-31 11:43:27 UTC
  • mto: (13813.5.2 librarian-disco)
  • mto: This revision was merged to the branch mainline in revision 13863.
  • Revision ID: stuart.bishop@canonical.com-20110831114327-4tr568l4udecltl3
Review feedback

Show diffs side-by-side

added added

removed removed

Lines of Context:
286
286
    """Ensure branch-rewrite.py survives fastdowntime deploys."""
287
287
    layer = LaunchpadScriptLayer
288
288
 
289
 
    def setUp(self):
290
 
        super(TestBranchRewriterScriptHandlesDisconnects, self).setUp()
291
 
        self.pgbouncer = PGBouncerFixture()
292
 
        self.addCleanup(self.pgbouncer.cleanUp)
293
 
        self.pgbouncer.setUp()
294
 
 
295
289
    def spawn(self):
296
290
        script_file = os.path.join(
297
291
            config.root, 'scripts', 'branch-rewrite.py')
300
294
            [script_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
301
295
            stderr=subprocess.PIPE, bufsize=0)
302
296
 
 
297
        self.addCleanup(self.rewriter_proc.terminate)
 
298
 
303
299
    def request(self, query):
304
300
        self.rewriter_proc.stdin.write(query + '\n')
305
301
        return self.rewriter_proc.stdout.readline().rstrip('\n')
306
302
 
307
 
    def test_disconnect(self):
 
303
    def test_reconnects_when_disconnected(self):
 
304
        pgbouncer = self.useFixture(PGBouncerFixture())
 
305
 
308
306
        self.spawn()
309
307
 
310
308
        # Everything should be working, and we get valid output.
311
309
        out = self.request('foo')
312
 
        assert out.endswith('/foo'), out
 
310
        self.assertEndsWith(out, '/foo')
313
311
 
314
 
        self.pgbouncer.stop()
 
312
        pgbouncer.stop()
315
313
 
316
314
        # Now with pgbouncer down, we should get NULL messages and
317
315
        # stderr spam, and this keeps happening. We test more than
319
317
        # after several failures.
320
318
        for count in range(5):
321
319
            out = self.request('foo')
322
 
            assert out == 'NULL', out
 
320
            self.assertEqual(out, 'NULL')
323
321
 
324
 
        self.pgbouncer.start()
 
322
        pgbouncer.start()
325
323
 
326
324
        # Everything should be working, and we get valid output.
327
325
        out = self.request('foo')
328
 
        assert out.endswith('/foo'), out
 
326
        self.assertEndsWith(out, '/foo')
329
327
 
330
328
    def test_starts_with_db_down(self):
331
 
        self.pgbouncer.stop()
 
329
        pgbouncer = self.useFixture(PGBouncerFixture())
 
330
 
 
331
        # Start with the database down.
 
332
        pgbouncer.stop()
 
333
 
332
334
        self.spawn()
333
335
 
334
336
        for count in range(5):
335
337
            out = self.request('foo')
336
 
            assert out == 'NULL', out
 
338
            self.assertEqual(out, 'NULL')
337
339
 
338
 
        self.pgbouncer.start()
 
340
        pgbouncer.start()
339
341
 
340
342
        out = self.request('foo')
341
 
        assert out.endswith('/foo'), out
 
343
        self.assertEndsWith(out, '/foo')