def test_getLogChunks(self): fixture = LibrarianServerFixture(BaseLayer.config_fixture) with fixture: chunks = fixture.getLogChunks() self.assertIsInstance(chunks, list) found_started = False for chunk in chunks: if 'daemon ready' in chunk: found_started = True self.assertTrue(found_started)
def test_smoke_test(self): # Avoid indefinite hangs: self.addCleanup(socket.setdefaulttimeout, socket.getdefaulttimeout()) socket.setdefaulttimeout(1) fixture = LibrarianServerFixture(BaseLayer.config_fixture) with fixture: librarian_url = "http://%s:%d" % ( config.librarian.download_host, fixture.download_port) restricted_librarian_url = "http://%s:%d" % ( config.librarian.restricted_download_host, fixture.restricted_download_port) # Both download ports work: self.assertIn('Copyright', urlopen(librarian_url).read()) self.assertIn( 'Copyright', urlopen(restricted_librarian_url).read()) os.path.isdir(fixture.root) # Ports are closed on cleanUp. self.assertRaises(IOError, urlopen, librarian_url) self.assertRaises(IOError, urlopen, restricted_librarian_url) self.assertFalse(os.path.exists(fixture.root)) # We can use the fixture again (gets a new URL): with fixture: librarian_url = "http://%s:%d" % ( config.librarian.download_host, fixture.download_port) self.assertIn('Copyright', urlopen(librarian_url).read())
def main(): args = sys.argv[1:] if '-h' in args or '--help' in args: print(__doc__) return 0 # Tell lp.services.config to use the testrunner config instance, so that # we don't kill the real services. config.setInstance('testrunner') config.generate_overrides() print("Killing Memcached....", end="") kill_by_pidfile(MemcachedLayer.getPidFile()) print("done.") print("Killing Librarian....", end="") librarian_fixture = LibrarianServerFixture(None) kill_by_pidfile(librarian_fixture.pidfile) librarian_fixture.tearDownRoot() print("done.") return 0
def test_setUp_allocates_resources(self): # We need a new ConfigFixture, and create a # LibrarianServerFixture using it. We can then confirm that new # resources have been allocated by comparing with the currently # in use ConfigFixture and config. config_fixture = ConfigFixture( 'foo', BaseLayer.config_fixture.instance_name) self.addCleanup(config_fixture.cleanUp) config_fixture.setUp() fixture = LibrarianServerFixture(config_fixture) self.skip_if_persistent(fixture) with fixture: try: self.assertNotEqual(config.librarian_server.root, fixture.root) self.assertNotEqual( config.librarian.download_port, fixture.download_port) self.assertNotEqual( config.librarian.upload_port, fixture.upload_port) self.assertNotEqual( config.librarian.restricted_download_port, fixture.restricted_download_port) self.assertNotEqual( config.librarian.restricted_upload_port, fixture.restricted_upload_port) # And it exposes a config fragment (but it is not activated). expected_config = dedent("""\ [librarian_server] root: %s [librarian] download_port: %s upload_port: %s download_url: http://%s:%s/ restricted_download_port: %s restricted_upload_port: %s restricted_download_url: http://%s:%s/ """) % ( fixture.root, fixture.download_port, fixture.upload_port, config.librarian.download_host, fixture.download_port, fixture.restricted_download_port, fixture.restricted_upload_port, config.librarian.restricted_download_host, fixture.restricted_download_port, ) self.assertEqual(expected_config, fixture.service_config) except: self.attachLibrarianLog(fixture) raise
def setUp(cls): # Fixture to hold other fixtures. cls._fixture = Fixture() cls._fixture.setUp() cls.pgbouncer_fixture = PGBouncerFixture() # Install the PGBouncer fixture so we shut it down to # create database outages. cls._fixture.useFixture(cls.pgbouncer_fixture) # Bring up the Librarian, which will be connecting via # pgbouncer. cls.librarian_fixture = LibrarianServerFixture( BaseLayer.config_fixture) cls._fixture.useFixture(cls.librarian_fixture)
def test_on_init_no_pid(self): fixture = LibrarianServerFixture(BaseLayer.config_fixture) self.skip_if_persistent(fixture) self.assertEqual(None, fixture.pid)