def setUp(self) -> None:
     super(TestWorkflowSubscriber, 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 warnings == 0
     self.task_pool.release_runahead_tasks()
     self.scheduler.ws_data_mgr.initiate_data_model()
     self.workflow_id = self.scheduler.ws_data_mgr.workflow_id
     self.publisher = WorkflowPublisher(
         self.suite_name, threaded=False, daemon=True)
     self.publisher.start(*PORT_RANGE)
     self.subscriber = WorkflowSubscriber(
         self.suite_name,
         host=self.scheduler.host,
         port=self.publisher.port,
         topics=[b'workflow'])
     # delay to allow subscriber to connection,
     # otherwise it misses the first message
     sleep(1.0)
     self.topic = None
     self.data = None
Beispiel #2
0
 def setUp(self) -> None:
     super(TestWorkflowPublisher, 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
     self.publisher = WorkflowPublisher(self.suite_name,
                                        threaded=False,
                                        daemon=True)
     self.pub_data = self.scheduler.ws_data_mgr.get_publish_deltas()
Beispiel #3
0
def test_start_stop(port_range):
    pub = WorkflowPublisher('beef')
    assert not pub.loop
    pub.start(*port_range)
    sleep(1)  # TODO - remove this evil sleep
    assert not pub.socket.closed
    assert pub.loop
    pub.stop()
    assert pub.socket.closed
class TestWorkflowSubscriber(CylcWorkflowTestCase):
    """Test the subscriber class components."""

    suite_name = "five"
    suiterc = """
[meta]
    title = "Inter-cycle dependence + a cold-start task"
[cylc]
    UTC mode = True
[scheduling]
    #runahead limit = 120
    initial cycle point = 20130808T00
    final cycle point = 20130812T00
    [[graph]]
        R1 = "prep => foo"
        PT12H = "foo[-PT12H] => foo => bar"
[visualization]
    initial cycle point = 20130808T00
    final cycle point = 20130808T12
    [[node attributes]]
        foo = "color=red"
        bar = "color=blue"

    """

    def setUp(self) -> None:
        super(TestWorkflowSubscriber, 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 warnings == 0
        self.task_pool.release_runahead_tasks()
        self.scheduler.ws_data_mgr.initiate_data_model()
        self.workflow_id = self.scheduler.ws_data_mgr.workflow_id
        self.publisher = WorkflowPublisher(
            self.suite_name, threaded=False, daemon=True)
        self.publisher.start(*PORT_RANGE)
        self.subscriber = WorkflowSubscriber(
            self.suite_name,
            host=self.scheduler.host,
            port=self.publisher.port,
            topics=[b'workflow'])
        # delay to allow subscriber to connection,
        # otherwise it misses the first message
        sleep(1.0)
        self.topic = None
        self.data = None

    def tearDown(self):
        self.subscriber.stop()
        self.publisher.stop()

    def test_constructor(self):
        """Test class constructor result."""
        self.assertIsNotNone(self.subscriber.context)
        self.assertFalse(self.subscriber.socket.closed)

    def test_subscribe(self):
        """Test publishing data."""
        pub_data = self.scheduler.ws_data_mgr.get_publish_deltas()
        self.publisher.publish(pub_data)

        def msg_process(btopic, msg):
            self.subscriber.stopping = True
            self.topic, self.data = process_delta_msg(btopic, msg, None)
        self.subscriber.loop.run_until_complete(
            self.subscriber.subscribe(msg_process))
        self.assertEqual(self.data.id, self.workflow_id)
Beispiel #5
0
class TestWorkflowPublisher(CylcWorkflowTestCase):

    suite_name = "five"
    suiterc = """
[meta]
    title = "Inter-cycle dependence + a cold-start task"
[cylc]
    UTC mode = True
[scheduling]
    #runahead limit = 120
    initial cycle point = 20130808T00
    final cycle point = 20130812T00
    [[graph]]
        R1 = "prep => foo"
        PT12H = "foo[-PT12H] => foo => bar"
[visualization]
    initial cycle point = 20130808T00
    final cycle point = 20130808T12
    [[node attributes]]
        foo = "color=red"
        bar = "color=blue"

    """

    def setUp(self) -> None:
        super(TestWorkflowPublisher, 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
        self.publisher = WorkflowPublisher(self.suite_name,
                                           threaded=False,
                                           daemon=True)
        self.pub_data = self.scheduler.ws_data_mgr.get_publish_deltas()

    def tearDown(self):
        self.publisher.stop()

    def test_constructor(self):
        self.assertFalse(self.publisher.threaded)
        self.assertIsNotNone(self.publisher.pattern)

    def test_publish(self):
        """Test publishing data."""
        self.publisher.start(*PORT_RANGE)
        subscriber = WorkflowSubscriber(self.suite_name,
                                        host=self.scheduler.host,
                                        port=self.publisher.port,
                                        topics=[b'workflow'])
        # delay to allow subscriber to connection,
        # otherwise it misses the first message
        sleep(1.0)
        self.publisher.publish(self.pub_data)
        btopic, msg = subscriber.loop.run_until_complete(
            subscriber.socket.recv_multipart())
        delta = DELTAS_MAP[btopic.decode('utf-8')]()
        delta.ParseFromString(msg)
        self.assertEqual(delta.id, self.workflow_id)
        subscriber.stop()
        with self.assertLogs(LOG, level='ERROR') as cm:
            self.publisher.publish(None)
        self.assertIn('publish: ', cm.output[0])

    def test_start(self):
        """Test publisher start."""
        self.assertIsNone(self.publisher.loop)
        self.assertIsNone(self.publisher.port)
        self.publisher.start(*PORT_RANGE)
        self.assertIsNotNone(self.publisher.loop)
        self.assertIsNotNone(self.publisher.port)
        self.publisher.stop()

    def test_stop(self):
        """Test publisher stop."""
        self.publisher.start(*PORT_RANGE)
        self.assertFalse(self.publisher.socket.closed)
        self.publisher.stop()
        self.assertTrue(self.publisher.socket.closed)