예제 #1
0
 def test_checks_for_dups_globally(self):
     flo = gf.Flow("test").add(
         gf.Flow("int1").add(test_utils.DummyTask(name="a")),
         gf.Flow("int2").add(test_utils.DummyTask(name="a")))
     e = engines.load(flo)
     self.assertRaisesRegex(exc.Duplicate, '^Atoms with duplicate names',
                            e.compile)
예제 #2
0
 def _create_engine(**kwargs):
     flow = lf.Flow('test-flow').add(utils.DummyTask())
     backend = backends.fetch({'connection': 'memory'})
     flow_detail = pu.create_flow_detail(flow, backend=backend)
     options = kwargs.copy()
     return engine.ParallelActionEngine(flow, flow_detail,
                                        backend, options)
예제 #3
0
    def setUp(self):
        super(TestWorkerTaskExecutor, self).setUp()
        self.task = test_utils.DummyTask()
        self.task_uuid = 'task-uuid'
        self.task_args = {'a': 'a'}
        self.task_result = 'task-result'
        self.task_failures = {}
        self.timeout = 60
        self.broker_url = 'broker-url'
        self.executor_uuid = 'executor-uuid'
        self.executor_exchange = 'executor-exchange'
        self.executor_topic = 'test-topic1'
        self.proxy_started_event = threading.Event()

        # patch classes
        self.proxy_mock, self.proxy_inst_mock = self.patchClass(
            executor.proxy, 'Proxy')
        self.request_mock, self.request_inst_mock = self.patchClass(
            executor.pr, 'Request', autospec=False)

        # other mocking
        self.proxy_inst_mock.start.side_effect = self._fake_proxy_start
        self.proxy_inst_mock.stop.side_effect = self._fake_proxy_stop
        self.request_inst_mock.uuid = self.task_uuid
        self.request_inst_mock.expired = False
        self.request_inst_mock.created_on = 0
        self.request_inst_mock.task_cls = self.task.name
        self.message_mock = mock.MagicMock(name='message')
        self.message_mock.properties = {
            'correlation_id': self.task_uuid,
            'type': pr.RESPONSE
        }
예제 #4
0
 def setUp(self):
     super(TestProtocol, self).setUp()
     self.task = utils.DummyTask()
     self.task_uuid = 'task-uuid'
     self.task_action = 'execute'
     self.task_args = {'a': 'a'}
     self.timeout = 60
예제 #5
0
 def test_request_invalid_action(self):
     request = pr.Request(utils.DummyTask("hi"),
                          uuidutils.generate_uuid(),
                          pr.EXECUTE, {}, 1.0)
     request = request.to_dict()
     request['action'] = 'NOTHING'
     self.assertRaises(excp.InvalidFormat, pr.Request.validate, request)
예제 #6
0
    def test_send_and_dispatch(self):
        details_capture = []

        t = test_utils.DummyTask("rcver")
        t.notifier.register(
            task.EVENT_UPDATE_PROGRESS,
            lambda _event_type, details: details_capture.append(details))

        d = pu.Dispatcher({}, b'secret', b'server-josh')
        d.setup()
        d.targets[b'child-josh'] = t

        s = threading.Thread(target=asyncore.loop, kwargs={'map': d.map})
        s.start()
        self.addCleanup(s.join)

        c = pu.Channel(d.port, b'child-josh', b'secret')
        self.addCleanup(c.close)

        send_what = [
            {
                'progress': 0.1
            },
            {
                'progress': 0.2
            },
            {
                'progress': 0.3
            },
            {
                'progress': 0.4
            },
            {
                'progress': 0.5
            },
            {
                'progress': 0.6
            },
            {
                'progress': 0.7
            },
            {
                'progress': 0.8
            },
            {
                'progress': 0.9
            },
        ]
        e_s = pu.EventSender(c)
        for details in send_what:
            e_s(task.EVENT_UPDATE_PROGRESS, details)

        # This forces the thread to shutdown (since the asyncore loop
        # will exit when no more sockets exist to process...)
        d.close()

        self.assertEqual(len(send_what), len(details_capture))
        self.assertEqual(send_what, details_capture)
예제 #7
0
 def test_task(self):
     task = test_utils.DummyTask(name='a')
     g = _replicate_graph_with_names(
         compiler.PatternCompiler(task).compile())
     self.assertEqual(['a'], list(g.nodes()))
     self.assertEqual([], list(g.edges()))
예제 #8
0
    def test_multi_message(self):
        message_count = 30
        barrier = latch.Latch(message_count)
        countdown = lambda data, message: barrier.countdown()

        on_notify = mock.MagicMock()
        on_notify.side_effect = countdown

        on_response = mock.MagicMock()
        on_response.side_effect = countdown

        on_request = mock.MagicMock()
        on_request.side_effect = countdown

        handlers = {
            pr.NOTIFY: dispatcher.Handler(on_notify),
            pr.RESPONSE: dispatcher.Handler(on_response),
            pr.REQUEST: dispatcher.Handler(on_request),
        }
        p = proxy.Proxy(TEST_TOPIC,
                        TEST_EXCHANGE,
                        handlers,
                        transport='memory',
                        transport_options={
                            'polling_interval': POLLING_INTERVAL,
                        })

        t = threading_utils.daemon_thread(p.start)
        t.start()
        p.wait()

        for i in range(0, message_count):
            j = i % 3
            if j == 0:
                p.publish(pr.Notify(), TEST_TOPIC)
            elif j == 1:
                p.publish(pr.Response(pr.RUNNING), TEST_TOPIC)
            else:
                p.publish(
                    pr.Request(test_utils.DummyTask("dummy_%s" % i),
                               uuidutils.generate_uuid(), pr.EXECUTE, [],
                               None), TEST_TOPIC)

        self.assertTrue(barrier.wait(test_utils.WAIT_TIMEOUT))
        self.assertEqual(0, barrier.needed)
        p.stop()
        t.join()

        self.assertTrue(on_notify.called)
        self.assertTrue(on_response.called)
        self.assertTrue(on_request.called)

        self.assertEqual(10, on_notify.call_count)
        self.assertEqual(10, on_response.call_count)
        self.assertEqual(10, on_request.call_count)

        call_count = sum([
            on_notify.call_count,
            on_response.call_count,
            on_request.call_count,
        ])
        self.assertEqual(message_count, call_count)
예제 #9
0
def my_flow_factory(task_name):
    return test_utils.DummyTask(name=task_name)
예제 #10
0
 def test_request(self):
     request = pr.Request(utils.DummyTask("hi"),
                          uuidutils.generate_uuid(),
                          pr.EXECUTE, {}, 1.0)
     pr.Request.validate(request.to_dict())