def test_worker_started_with_required_arguments(self, mock_worker, setup_logging_mock): concurrency = '1' celery_hostname = "celery_hostname" queues = "queue" autoscale = "2,5" args = self.parser.parse_args([ 'worker', '--autoscale', autoscale, '--concurrency', concurrency, '--celery_hostname', celery_hostname, '--queues', queues ]) with mock.patch('celery.platforms.check_privileges') as mock_privil: mock_privil.return_value = 0 cli.worker(args) mock_worker.return_value.run.assert_called_once_with( pool='prefork', optimization='fair', O='fair', # noqa queues=queues, concurrency=int(concurrency), autoscale=autoscale, hostname=celery_hostname, loglevel=mock.ANY, )
def test_error(self, mock_validate_session): """ Test to verify the exit mechanism of airflow-worker cli by mocking validate_session method """ mock_validate_session.return_value = False with self.assertRaises(SystemExit) as cm: # airflow.bin.cli.worker(mock_args) cli.worker(mock_args) self.assertEqual(cm.exception.code, 1)
def test_error(self, mock_validate_session): """ Test to verify the exit mechanism of airflow-worker cli by mocking validate_session method """ mock_validate_session.return_value = False with self.assertRaises(SystemExit) as cm: # airflow.bin.cli.worker(mock_args) cli.worker(mock_args) self.assertEqual(cm.exception.code, 1)
def test_skip_serve_logs_on_worker_start(self, celery_mock): with patch('airflow.bin.cli.subprocess.Popen') as mock_popen: mock_popen.return_value.communicate.return_value = (b'output', b'error') mock_popen.return_value.returncode = 0 args = self.parser.parse_args(['worker', '-c', '-1', '-s']) with patch('celery.platforms.check_privileges') as mock_privil: mock_privil.return_value = 0 cli.worker(args) mock_popen.assert_not_called()