def setUp(self) -> None: super(TestSuiteRuntimeServer, self).setUp() self.scheduler.ws_data_mgr = DataStoreMgr(self.scheduler) for name in self.scheduler.config.taskdefs: task_proxy = create_task_proxy(task_name=name, suite_config=self.suite_config, is_startup=True) warnings = self.task_pool.insert_tasks(items=[task_proxy.identity], stopcp=None, no_check=False) assert 0 == warnings self.task_pool.release_runahead_tasks() self.scheduler.ws_data_mgr.initiate_data_model() self.workflow_id = self.scheduler.ws_data_mgr.workflow_id create_auth_files(self.suite_name) # auth keys are required for comms barrier = Barrier(2, timeout=10) self.server = SuiteRuntimeServer(self.scheduler, context=SERVER_CONTEXT, threaded=True, barrier=barrier, daemon=True) self.server.public_priv = Priv.CONTROL self.server.start(*PORT_RANGE) # barrier.wait() doesn't seem to work properly here # so this workaround will do while barrier.n_waiting < 1: sleep(0.2) barrier.wait() sleep(0.5)
def scheduler_cli(parser, options, args, is_restart=False): """CLI main.""" reg = args[0] # Check suite is not already running before start of host selection. try: suite_files.detect_old_contact_file(reg) except SuiteServiceFileError as exc: sys.exit(exc) suite_run_dir = get_suite_run_dir(reg) if not os.path.exists(suite_run_dir): sys.stderr.write(f'suite service directory not found ' f'at: {suite_run_dir}\n') sys.exit(1) # Create auth files if needed. suite_files.create_auth_files(reg) # Extract job.sh from library, for use in job scripts. extract_resources(suite_files.get_suite_srv_dir(reg), ['etc/job.sh']) # Check whether a run host is explicitly specified, else select one. if not options.host: try: host = HostAppointer().appoint_host() except EmptyHostList as exc: if cylc.flow.flags.debug: raise else: sys.exit(str(exc)) if is_remote_host(host): if is_restart: base_cmd = ["restart"] + sys.argv[1:] else: base_cmd = ["run"] + sys.argv[1:] # Prevent recursive host selection base_cmd.append("--host=localhost") return remote_cylc_cmd(base_cmd, host=host) if remrun(set_rel_local=True): # State localhost as above. sys.exit() try: suite_files.get_suite_source_dir(args[0], options.owner) except SuiteServiceFileError: # Source path is assumed to be the run directory suite_files.register(args[0], get_suite_run_dir(args[0])) try: scheduler = Scheduler(is_restart, options, args) except SuiteServiceFileError as exc: sys.exit(exc) scheduler.start()
def test_stop(): """Test socket/thread stop.""" create_auth_files('test_zmq_stop') # auth keys are required for comms barrier = Barrier(2, timeout=20) publisher = ZMQSocketBase(zmq.PUB, suite='test_zmq_stop', bind=True, barrier=barrier, threaded=True, daemon=True) publisher.start(*PORT_RANGE) # barrier.wait() doesn't seem to work properly here # so this workaround will do while publisher.barrier.n_waiting < 1: sleep(0.2) barrier.wait() assert not publisher.socket.closed assert publisher.thread.is_alive() publisher.stop() assert publisher.socket.closed assert not publisher.thread.is_alive()
def test_start(): """Test socket start.""" create_auth_files('test_zmq_start') # auth keys are required for comms barrier = Barrier(2, timeout=20) publisher = ZMQSocketBase(zmq.PUB, suite='test_zmq_start', bind=True, barrier=barrier, threaded=True, daemon=True) assert publisher.barrier.n_waiting == 0 assert publisher.loop is None assert publisher.port is None publisher.start(*PORT_RANGE) # barrier.wait() doesn't seem to work properly here # so this workaround will do while publisher.barrier.n_waiting < 1: sleep(0.2) assert barrier.wait() == 1 assert publisher.loop is not None assert publisher.port is not None publisher.stop()
def test_single_port(): """Test server on a single port and port in use exception.""" context = zmq.Context() create_auth_files('test_zmq') # auth keys are required for comms serv1 = ZMQSocketBase( zmq.REP, context=context, suite='test_zmq', bind=True) serv2 = ZMQSocketBase( zmq.REP, context=context, suite='test_zmq', bind=True) serv1._socket_bind(*PORT_RANGE) port = serv1.port with pytest.raises(CylcError, match=r"Address already in use") as exc: serv2._socket_bind(port, port) serv2.stop() serv1.stop() context.destroy()
def setUp(self) -> None: super(TestSuiteRuntimeClient, self).setUp() self.scheduler.data_store_mgr = DataStoreMgr(self.scheduler) for name in self.scheduler.config.taskdefs: task_proxy = create_task_proxy( task_name=name, suite_config=self.suite_config, is_startup=True ) warnings = self.task_pool.insert_tasks( items=[task_proxy.identity], stopcp=None, check_point=True ) assert warnings == 0 self.task_pool.release_runahead_tasks() self.scheduler.data_store_mgr.initiate_data_model() self.workflow_id = self.scheduler.data_store_mgr.workflow_id create_auth_files(self.suite_name) # auth keys are required for comms barrier = Barrier(2, timeout=20) self.server = SuiteRuntimeServer( self.scheduler, context=SERVER_CONTEXT, threaded=True, barrier=barrier, daemon=True) port_range = glbl_cfg().get(['suite servers', 'run ports']) self.server.start(port_range[0], port_range[-1]) # barrier.wait() doesn't seem to work properly here # so this workaround will do while barrier.n_waiting < 1: sleep(0.2) barrier.wait() sleep(0.5) self.client = SuiteRuntimeClient( self.scheduler.suite, host=self.scheduler.host, port=self.server.port) sleep(0.5)