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 = RegionAllInOneServiceMaker("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 = RegionAllInOneServiceMaker("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 = [ # Worker services. "database-tasks", "postgres-listener-worker", "rack-controller", "rpc", "service-monitor", "status-worker", "web", "ipc-worker", # Master services. "region-controller", "nonce-cleanup", "dns-publication-cleanup", "status-monitor", "stats", "prometheus", "prometheus-exporter", "import-resources", "import-resources-progress", "postgres-listener-master", "networks-monitor", "active-discovery", "reverse-dns", "ntp", "syslog", # "workers", Prevented in all-in-one. "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())