コード例 #1
0
    def test_setup(self, register_worker_mock):
        worker = BaseWorker()
        worker.setup()

        self.assertTrue(worker.id)
        self.assertTrue(worker.uuid)
        self.assertAlmostEqual(worker.created_dt, now(), delta=datetime.timedelta(seconds=1))
        self.assertTrue(worker.host_name)
        self.assertTrue(register_worker_mock.called)
コード例 #2
0
    def test_setup(self, register_worker_mock):
        worker = BaseWorker()
        worker.setup()

        self.assertTrue(worker.id)
        self.assertTrue(worker.uuid)
        self.assertAlmostEqual(worker.created_dt,
                               now(),
                               delta=datetime.timedelta(seconds=1))
        self.assertTrue(worker.host_name)
        self.assertTrue(register_worker_mock.called)
コード例 #3
0
    def test_register_worker(self, context_mock):
        answer_data = {'scheduler_port': 123}
        register_socket_mock = context_mock.return_value.socket.return_value
        register_socket_mock.recv_string.return_value = json.dumps(answer_data)

        worker = BaseWorker()
        worker._init_worker()
        worker._register_worker()

        self.assertTrue(register_socket_mock.send_string.called)
        self.assertEqual(worker.scheduler_port, answer_data['scheduler_port'])
コード例 #4
0
    def test_heart_beat(self, sleep_mock, emit_mock, is_stopped_mock):
        is_stopped_mock.side_effect = (False, True)
        worker = BaseWorker()
        worker._init_worker()

        worker._heart_beat()

        self.assertEqual(WORKER_EVENT, emit_mock.call_args[0][0])
        worker_data = json.loads(emit_mock.call_args[0][1], object_hook=json_util.object_hook)
        self.assertAlmostEqual(
            now(),
            worker_data['heart_beat_dt'],
            delta=datetime.timedelta(seconds=1)
        )
コード例 #5
0
 def create_worker(self):
     worker = BaseWorker()
     worker.ZMQ_SERVER_ADDRESS = 'test'
     worker.ZMQ_WORKER_REGISTRATOR_PORT = 321
     worker.scheduler_port = 123
     worker._init_worker()
     return worker
コード例 #6
0
 def create_worker(self):
     worker = BaseWorker()
     worker.ZMQ_SERVER_ADDRESS = 'test'
     worker.ZMQ_WORKER_REGISTRATOR_PORT = 321
     worker.scheduler_port = 123
     worker._init_worker()
     return worker
コード例 #7
0
    def test_register_worker(self, context_mock):
        answer_data = {'scheduler_port': 123}
        register_socket_mock = context_mock.return_value.socket.return_value
        register_socket_mock.recv_string.return_value = json.dumps(answer_data)

        worker = BaseWorker()
        worker._init_worker()
        worker._register_worker()

        self.assertTrue(register_socket_mock.send_string.called)
        self.assertEqual(worker.scheduler_port, answer_data['scheduler_port'])
コード例 #8
0
    def test_heart_beat(self, sleep_mock, emit_mock, is_stopped_mock):
        is_stopped_mock.side_effect = (False, True)
        worker = BaseWorker()
        worker._init_worker()

        worker._heart_beat()

        self.assertEqual(WORKER_EVENT, emit_mock.call_args[0][0])
        worker_data = json.loads(emit_mock.call_args[0][1],
                                 object_hook=json_util.object_hook)
        self.assertAlmostEqual(now(),
                               worker_data['heart_beat_dt'],
                               delta=datetime.timedelta(seconds=1))
コード例 #9
0
 def test_prepare_task_options(self):
     data = self.monit_task.get_data()
     task_name, task_options = BaseWorker._prepare_task_options(
         data['task'], self.monit_task.get_task_type())
     self.assertEqual(self.monit_task.get_name(), task_name)
     self.assertEqual({'host': self.monit_task.host_address}, task_options)
コード例 #10
0
 def test_prepare_task_options(self):
     data = self.monit_task.get_data()
     task_name, task_options = BaseWorker._prepare_task_options(data['task'], self.monit_task.get_task_type())
     self.assertEqual(self.monit_task.get_name(), task_name)
     self.assertEqual({'host': self.monit_task.host_address}, task_options)