Exemplo n.º 1
0
    def test_master_args_correctly_create_cluster_master(self):
        mock_cluster_master = self.mock_ClusterMaster.return_value  # get the mock for the ClusterMaster instance

        main.main(['master'])

        self.mock_ClusterMaster.assert_called_once_with()  # assert on constructor params
        self.mock_ClusterMasterApplication.assert_called_once_with(mock_cluster_master)  # assert on constructor params
Exemplo n.º 2
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_via_unhandled_exception(self):
        run_mock = self.patch('app.__main__.MasterSubcommand').return_value.run
        run_mock.side_effect = Exception('I am here to trigger teardown handlers!')

        with self.assertRaises(SystemExit, msg='UnhandledExceptionHandler should convert Exception to SystemExit.'):
            main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(seconds=AnythingOfType(int))
Exemplo n.º 3
0
    def test_single_machine_case_runs_master_and_slave(self):
        mock_service_runner = self.mock_ServiceRunner.return_value
        mock_service_runner.is_master_up.return_value = False
        build_args = ['build']

        main.main(build_args)

        self.assertTrue(mock_service_runner.run_master.called)
        self.assertTrue(mock_service_runner.run_slave.called)
Exemplo n.º 4
0
    def test_single_machine_case_runs_master_and_slave(self):
        mock_service_runner = self.mock_ServiceRunner.return_value
        mock_service_runner.is_master_up.return_value = False
        build_args = ['build']

        main.main(build_args)

        self.assertTrue(mock_service_runner.run_master.called)
        self.assertTrue(mock_service_runner.run_slave.called)
Exemplo n.º 5
0
    def test_master_args_correctly_create_cluster_master(self):
        mock_cluster_master = self.mock_ClusterMaster.return_value  # get the mock for the ClusterMaster instance

        main.main(['master'])

        self.mock_ClusterMaster.assert_called_once_with(
        )  # assert on constructor params
        self.mock_ClusterMasterApplication.assert_called_once_with(
            mock_cluster_master)  # assert on constructor params
Exemplo n.º 6
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_normally(
            self):
        self.patch('app.__main__.MasterSubcommand'
                   )  # causes subcommand run() method to return immediately

        main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(
            seconds=AnythingOfType(int))
Exemplo n.º 7
0
    def test_explicit_slave_args_correctly_create_cluster_slave(self):
        mock_cluster_slave = self.mock_ClusterSlave.return_value

        main.main(['slave', '--num-executors', '5', '--port', '98765'])

        expected_cluster_slave_constructor_args = {
            'num_executors': 5,
            'port': 98765,
            'host': Configuration['hostname'],
        }
        self.mock_ClusterSlave.assert_called_once_with(**expected_cluster_slave_constructor_args)
        self.mock_ClusterSlaveApplication.assert_called_once_with(mock_cluster_slave)
Exemplo n.º 8
0
    def test_valid_args_for_build_will_correctly_instantiate_build_runner(self, extra_args, expected_request_params):
        def secret_setter(*args):
            Secret.set('mellon1234')
        main._set_secret = Mock(side_effect=secret_setter)
        build_args = ['build', '--master-url', 'smaug:1'] + extra_args
        expected_request_params['job_name'] = None
        self.patch('app.__main__.util.project_type_subclasses_by_name').return_value = {  # mock out project_type subclasses
            'imaginary': _ImaginaryProjectType,
        }

        main.main(build_args)
        self.mock_BuildRunner.assert_called_once_with(master_url='smaug:1',
                                                      request_params=expected_request_params, secret='mellon1234')
Exemplo n.º 9
0
    def test_default_slave_args_correctly_create_cluster_slave(self):
        self.mock_configuration_values({'num_executors': 1}, default_value='default_value')
        mock_cluster_slave = self.mock_ClusterSlave.return_value

        main.main(['slave'])

        expected_cluster_slave_constructor_args = {
            'num_executors': 1,
            'port': Configuration['port'],
            'host': Configuration['hostname'],
        }
        self.mock_ClusterSlave.assert_called_once_with(**expected_cluster_slave_constructor_args)
        self.mock_ClusterSlaveApplication.assert_called_once_with(mock_cluster_slave)
Exemplo n.º 10
0
    def test_explicit_slave_args_correctly_create_cluster_slave(self):
        mock_cluster_slave = self.mock_ClusterSlave.return_value

        main.main(['slave', '--num-executors', '5', '--port', '98765'])

        expected_cluster_slave_constructor_args = {
            'num_executors': 5,
            'port': 98765,
            'host': Configuration['hostname'],
        }
        self.mock_ClusterSlave.assert_called_once_with(
            **expected_cluster_slave_constructor_args)
        self.mock_ClusterSlaveApplication.assert_called_once_with(
            mock_cluster_slave)
Exemplo n.º 11
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_via_unhandled_exception(
            self):
        run_mock = self.patch('app.__main__.MasterSubcommand').return_value.run
        run_mock.side_effect = Exception(
            'I am here to trigger teardown handlers!')

        with self.assertRaises(
                SystemExit,
                msg=
                'UnhandledExceptionHandler should convert Exception to SystemExit.'
        ):
            main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(
            seconds=AnythingOfType(int))
Exemplo n.º 12
0
    def test_default_slave_args_correctly_create_cluster_slave(self):
        self.mock_configuration_values({'num_executors': 1},
                                       default_value='default_value')
        mock_cluster_slave = self.mock_ClusterSlave.return_value

        main.main(['slave'])

        expected_cluster_slave_constructor_args = {
            'num_executors': 1,
            'port': Configuration['port'],
            'host': Configuration['hostname'],
        }
        self.mock_ClusterSlave.assert_called_once_with(
            **expected_cluster_slave_constructor_args)
        self.mock_ClusterSlaveApplication.assert_called_once_with(
            mock_cluster_slave)
Exemplo n.º 13
0
    def test_valid_args_for_build_will_correctly_instantiate_build_runner(
            self, extra_args, expected_request_params):
        def secret_setter(*args):
            Secret.set('mellon1234')

        main._set_secret = Mock(side_effect=secret_setter)
        build_args = ['build', '--master-url', 'smaug:1'] + extra_args
        expected_request_params['job_name'] = None
        self.patch('app.__main__.util.project_type_subclasses_by_name').return_value = {  # mock out project_type subclasses
            'imaginary': _ImaginaryProjectType,
        }

        main.main(build_args)
        self.mock_BuildRunner.assert_called_once_with(
            master_url='smaug:1',
            request_params=expected_request_params,
            secret='mellon1234')
Exemplo n.º 14
0
#!/usr/bin/env python
from app.__main__ import main

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        pass
Exemplo n.º 15
0
from app import __main__

if __name__ == '__main__':
    __main__.main()
Exemplo n.º 16
0
from app import __main__ as run

run.main()
Exemplo n.º 17
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_normally(self):
        self.patch('app.__main__.MasterSubcommand')  # causes subcommand run() method to return immediately

        main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(seconds=AnythingOfType(int))