Пример #1
0
    def test_repr(self):
        pipeline_manager = PipelineManager(api=API_ADDRESS,
                                           broadcast=BROADCAST_ADDRESS)
        pipeline_ids = [uuid4().hex for i in range(10)]
        pipeline_ids_copy = pipeline_ids[:]
        pipeline_manager.send_api_request = lambda x: None
        pipeline_manager.get_api_reply = \
                lambda: {'pipeline id': pipeline_ids.pop()}
        pipelines = [Pipeline({Job('A', data={'index': i}): Job('B')}) \
                     for i in range(10)]
        for pipeline in pipelines:
            pipeline_manager.start(pipeline)

        result = repr(pipeline_manager)
        self.assertEqual(result, '<PipelineManager: 10 submitted, 0 finished>')

        messages = [
            'pipeline finished: id={}, duration=0.1'.format(pipeline_id)
            for pipeline_id in pipeline_ids_copy[:3]
        ]
        poll = [False, True, True, True]

        def new_poll(timeout):
            return poll.pop()

        def new_broadcast_receive():
            return messages.pop()

        pipeline_manager.broadcast_poll = new_poll
        pipeline_manager.broadcast_receive = new_broadcast_receive
        pipeline_manager.update(0.1)
        result = repr(pipeline_manager)
        self.assertEqual(result, '<PipelineManager: 10 submitted, 3 finished>')
Пример #2
0
    def test_repr(self):
        pipeline_manager = PipelineManager(api=API_ADDRESS,
                                           broadcast=BROADCAST_ADDRESS)
        pipeline_ids = [uuid4().hex for i in range(10)]
        pipeline_ids_copy = pipeline_ids[:]
        pipeline_manager.send_api_request = lambda x: None
        pipeline_manager.get_api_reply = \
                lambda: {'pipeline id': pipeline_ids.pop()}
        pipelines = [Pipeline({Job('A', data={'index': i}): Job('B')}) \
                     for i in range(10)]
        for pipeline in pipelines:
            pipeline_manager.start(pipeline)

        result = repr(pipeline_manager)
        self.assertEqual(result, '<PipelineManager: 10 submitted, 0 finished>')

        messages = ['pipeline finished: id={}, duration=0.1'.format(pipeline_id)
                    for pipeline_id in pipeline_ids_copy[:3]]
        poll = [False, True, True, True]
        def new_poll(timeout):
            return poll.pop()
        def new_broadcast_receive():
            return messages.pop()
        pipeline_manager.broadcast_poll = new_poll
        pipeline_manager.broadcast_receive = new_broadcast_receive
        pipeline_manager.update(0.1)
        result = repr(pipeline_manager)
        self.assertEqual(result, '<PipelineManager: 10 submitted, 3 finished>')
Пример #3
0
 def test_should_return_all_pipelines(self):
     pipeline_manager = PipelineManager(api=API_ADDRESS,
                                        broadcast=BROADCAST_ADDRESS)
     pipeline_manager.send_api_request = lambda x: None
     pipeline_manager.get_api_reply = lambda: {'pipeline id': uuid4().hex}
     iterations = 10
     pipelines = []
     for i in range(iterations):
         pipeline = Pipeline({Job(u'worker_1'): Job(u'worker_2'),
                              Job(u'worker_2'): Job(u'worker_3')},
                             data={'index': i})
         pipeline_manager.start(pipeline)
         pipelines.append(pipeline)
     self.assertEqual(set(pipeline_manager.pipelines), set(pipelines))
Пример #4
0
 def test_should_return_all_pipelines(self):
     pipeline_manager = PipelineManager(api=API_ADDRESS,
                                        broadcast=BROADCAST_ADDRESS)
     pipeline_manager.send_api_request = lambda x: None
     pipeline_manager.get_api_reply = lambda: {'pipeline id': uuid4().hex}
     iterations = 10
     pipelines = []
     for i in range(iterations):
         pipeline = Pipeline(
             {
                 Job(u'worker_1'): Job(u'worker_2'),
                 Job(u'worker_2'): Job(u'worker_3')
             },
             data={'index': i})
         pipeline_manager.start(pipeline)
         pipelines.append(pipeline)
     self.assertEqual(set(pipeline_manager.pipelines), set(pipelines))