def testUploadsSucceed(self): # This layer is able to be used on its own as it depends on # DatabaseLayer. # We can test this using remoteAddFile (it does not need the CA # loaded) client = LibrarianClient() data = 'This is a test' client.remoteAddFile( 'foo.txt', len(data), StringIO(data), 'text/plain')
def testUploadsSucceed(self): # This layer is able to be used on its own as it depends on # DatabaseLayer. # We can test this using remoteAddFile (it does not need the CA # loaded) client = LibrarianClient() data = 'This is a test' client.remoteAddFile('foo.txt', len(data), StringIO(data), 'text/plain')
def testHideLibrarian(self): # First perform a successful upload: client = LibrarianClient() data = 'foo' client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain') # The database was committed to, but not by this process, so we need # to ensure that it is fully torn down and recreated. DatabaseLayer.force_dirty_database() # Hide the librarian, and show that the upload fails: LibrarianLayer.hide() self.assertRaises(UploadFailed, client.remoteAddFile, 'foo', len(data), StringIO(data), 'text/plain') # Reveal the librarian again, allowing uploads: LibrarianLayer.reveal() client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain')
def testHideLibrarian(self): # First perform a successful upload: client = LibrarianClient() data = 'foo' client.remoteAddFile( 'foo', len(data), StringIO(data), 'text/plain') # The database was committed to, but not by this process, so we need # to ensure that it is fully torn down and recreated. DatabaseLayer.force_dirty_database() # Hide the librarian, and show that the upload fails: LibrarianLayer.hide() self.assertRaises(UploadFailed, client.remoteAddFile, 'foo', len(data), StringIO(data), 'text/plain') # Reveal the librarian again, allowing uploads: LibrarianLayer.reveal() client.remoteAddFile( 'foo', len(data), StringIO(data), 'text/plain')
def test_librarian_is_reset(self): # Add a file. We use remoteAddFile because it does not need the CA # loaded to work. client = LibrarianClient() LibrarianTestCase.url = client.remoteAddFile( self.sample_data, len(self.sample_data), StringIO(self.sample_data), 'text/plain') self.failUnlessEqual( urlopen(LibrarianTestCase.url).read(), self.sample_data) # Perform the librarian specific between-test code: LibrarianLayer.testTearDown() LibrarianLayer.testSetUp() # Which should have nuked the old file. # XXX: StuartBishop 2006-06-30 Bug=51370: # We should get a DownloadFailed exception here. data = urlopen(LibrarianTestCase.url).read() self.failIfEqual(data, self.sample_data)
class TestLibrarianDBOutage(TestCase): layer = PGBouncerLibrarianLayer def setUp(self): super(TestLibrarianDBOutage, self).setUp() self.pgbouncer = PGBouncerLibrarianLayer.pgbouncer_fixture self.client = LibrarianClient() # Add a file to the Librarian so we can download it. self.url = self._makeLibraryFileUrl() def _makeLibraryFileUrl(self): data = 'whatever' return self.client.remoteAddFile('foo.txt', len(data), StringIO(data), 'text/plain') def getErrorCode(self): # We need to talk to every Librarian thread to ensure all the # Librarian database connections are in a known state. # XXX StuartBishop 2011-09-01 bug=840046: 20 might be overkill # for the test run, but we have no real way of knowing how many # connections are in use. num_librarian_threads = 20 codes = set() for count in range(num_librarian_threads): try: urllib2.urlopen(self.url).read() codes.add(200) except urllib2.HTTPError as error: codes.add(error.code) self.assertTrue(len(codes) == 1, 'Mixed responses: %s' % str(codes)) return codes.pop() def test_outage(self): # Everything should be working fine to start with. self.assertEqual(self.getErrorCode(), 200) # When the outage kicks in, we start getting 503 responses # instead of 200 and 404s. self.pgbouncer.stop() self.assertEqual(self.getErrorCode(), 503) # When the outage is over, things are back to normal. self.pgbouncer.start() self.assertEqual(self.getErrorCode(), 200)
class TestLibrarianDBOutage(TestCase): layer = PGBouncerLibrarianLayer def setUp(self): super(TestLibrarianDBOutage, self).setUp() self.pgbouncer = PGBouncerLibrarianLayer.pgbouncer_fixture self.client = LibrarianClient() # Add a file to the Librarian so we can download it. self.url = self._makeLibraryFileUrl() def _makeLibraryFileUrl(self): data = "whatever" return self.client.remoteAddFile("foo.txt", len(data), StringIO(data), "text/plain") def getErrorCode(self): # We need to talk to every Librarian thread to ensure all the # Librarian database connections are in a known state. # XXX StuartBishop 2011-09-01 bug=840046: 20 might be overkill # for the test run, but we have no real way of knowing how many # connections are in use. num_librarian_threads = 20 codes = set() for count in range(num_librarian_threads): try: urllib2.urlopen(self.url).read() codes.add(200) except urllib2.HTTPError as error: codes.add(error.code) self.assertTrue(len(codes) == 1, "Mixed responses: %s" % str(codes)) return codes.pop() def test_outage(self): # Everything should be working fine to start with. self.assertEqual(self.getErrorCode(), 200) # When the outage kicks in, we start getting 503 responses # instead of 200 and 404s. self.pgbouncer.stop() self.assertEqual(self.getErrorCode(), 503) # When the outage is over, things are back to normal. self.pgbouncer.start() self.assertEqual(self.getErrorCode(), 200)
def test_librarian_is_reset(self): # Add a file. We use remoteAddFile because it does not need the CA # loaded to work. client = LibrarianClient() LibrarianTestCase.url = client.remoteAddFile( self.sample_data, len(self.sample_data), StringIO(self.sample_data), 'text/plain' ) self.failUnlessEqual( urlopen(LibrarianTestCase.url).read(), self.sample_data ) # Perform the librarian specific between-test code: LibrarianLayer.testTearDown() LibrarianLayer.testSetUp() # Which should have nuked the old file. # XXX: StuartBishop 2006-06-30 Bug=51370: # We should get a DownloadFailed exception here. data = urlopen(LibrarianTestCase.url).read() self.failIfEqual(data, self.sample_data)