Ejemplo n.º 1
0
    def test_managers_stop_shortly_after_the_last_host_has_disconnected(self):
        manager = spawn_detached_manager(
            config_file=ConfigFiles.MANAGER_LIFECYCLE)

        host1 = spawn_managed_host(ConfigFiles.MANAGER_LIFECYCLE, manager)

        self.assertTrue(host1.is_running())

        host2 = spawn_managed_host(ConfigFiles.MANAGER, manager)

        self.assertNotEqual(host1.get_config()['port'],
                            host2.get_config()['port'])

        self.assertTrue(host2.is_running())

        host1.disconnect()
        time.sleep(0.2)

        self.assertFalse(host1.is_running())
        self.assertTrue(manager.is_running())

        data = manager.request_host_status(host1.config_file)
        self.assertFalse(data['started'])

        self.assertTrue(manager.is_running())

        host2.disconnect()
        time.sleep(0.2)

        self.assertFalse(host2.is_running())

        self.assertFalse(manager.is_running())
Ejemplo n.º 2
0
    def test_if_a_managed_host_crashes_the_exception_points_to_the_logfile(
            self):
        manager = spawn_detached_manager(ConfigFiles.MANAGED_HOST_LIFECYCLE)

        host = spawn_managed_host(ConfigFiles.MANAGED_HOST_LIFECYCLE, manager)

        self.assertEqual(host.send_json_request('function/test').text, 'test')

        self.assertIsNotNone(host.logfile)

        host.stop()

        try:
            host.send_json_request('function/test')
        except ProcessError as e:
            self.assertIn(
                '{} appears to have crashed, you can inspect the log file at {}'
                .format(
                    host.get_name(),
                    host.logfile,
                ),
                str(e),
            )

        manager.stop()
Ejemplo n.º 3
0
    def test_functions_validate_the_hosts_config(self):
        function = Function('test')

        function.host = spawn_managed_host(config_file=ConfigFiles.NO_FUNCTIONS, manager=manager)

        self.assertEqual(function.host.get_config()['functions'], [])

        self.assertRaises(ConfigError, function.send_request)

        function.host.get_config()['functions'].append({'name': 'test'})
Ejemplo n.º 4
0
    def test_managed_host_lifecycle(self):
        manager = spawn_detached_manager(ConfigFiles.MANAGED_HOST_LIFECYCLE)

        self.assertEqual(manager.get_config()['port'], 23456)
        self.assertTrue(manager.is_running())

        host1 = spawn_managed_host(manager.config_file,
                                   manager,
                                   connect_on_start=False)

        self.assertNotEqual(host1.get_config()['port'],
                            manager.get_config()['port'])
        self.assertTrue(host1.is_running())

        host1.connect()

        self.assertTrue(host1.is_running())

        res = host1.send_json_request('function/test')
        self.assertEqual(res.text, 'test')

        host1.disconnect()
        self.assertTrue(host1.is_running())

        host2 = spawn_managed_host(manager.config_file, manager)

        self.assertIsInstance(host2.logfile, six.string_types)
        self.assertEqual(host2.get_name(), host1.get_name())
        self.assertEqual(host2.get_config()['port'],
                         host1.get_config()['port'])
        self.assertEqual(host2.logfile, host1.logfile)

        res = host2.send_json_request('function/test')
        self.assertEqual(res.text, 'test')

        host2.disconnect()
        self.assertTrue(host1.is_running())

        host2.stop()
        self.assertFalse(host2.is_running())
        self.assertRaises(UnexpectedResponse, host2.connect)

        manager.stop()
Ejemplo n.º 5
0
    def setUpClass(cls):
        cls.manager = spawn_detached_manager(ConfigFiles.BASE_JS)

        cls.host = spawn_managed_host(ConfigFiles.BASE_JS, cls.manager)