def test_disables_database_connections_in_reactor(self): self.assertConnectionsEnabled() service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(Options()) self.assertConnectionsDisabled()
def test_makeService_configures_pserv_debug(self): options = Options() service_maker = RegionMasterServiceMaker("Harry", "Hill") mock_pserv = self.patch(service_maker, "_configurePservSettings") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(options) self.assertThat(mock_pserv, MockCalledOnceWith())
def test_configures_thread_pool(self): # Patch and restore where it's visible because patching a running # reactor is potentially fairly harmful. patcher = monkey.MonkeyPatcher() patcher.add_patch(reactor, "threadpool", None) patcher.add_patch(reactor, "threadpoolForDatabase", None) patcher.patch() try: service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") service_maker.makeService(Options()) threadpool = reactor.getThreadPool() self.assertThat(threadpool, IsInstance(ThreadPool)) finally: patcher.restore()
def test_makeService(self): options = Options() service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service = service_maker.makeService(options) self.assertIsInstance(service, MultiService) expected_services = [ "region-controller", "nonce-cleanup", "dns-publication-cleanup", "service-monitor", "status-monitor", "stats", "postgres-listener-master", "networks-monitor", "active-discovery", "reverse-dns", "ntp", "workers", "ipc-master", ] self.assertItemsEqual(expected_services, service.namedServices.keys()) self.assertEqual( len(service.namedServices), len(service.services), "Not all services are named.") self.assertThat( logger.configure, MockCalledOnceWith( options["verbosity"], logger.LoggingMode.TWISTD)) self.assertThat(crochet.no_setup, MockCalledOnceWith())
def test_makeService_cleanup_prometheus_dir(self): tmpdir = Path(self.useFixture(TempDirectory()).path) self.useFixture( EnvironmentVariableFixture("prometheus_multiproc_dir", str(tmpdir)) ) pid = os.getpid() file1 = tmpdir / "histogram_{}.db".format(pid) file1.touch() file2 = tmpdir / "histogram_{}.db".format(self.get_unused_pid()) file2.touch() service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(Options()) self.assertTrue(file1.exists()) self.assertFalse(file2.exists())