Пример #1
0
async def verify_path_imports():
    test_env = {}
    request = protos.FunctionEnvironmentReloadRequest(
        environment_variables=test_env)

    request_msg = protos.StreamingMessage(
        request_id='0', function_environment_reload_request=request)

    disp = testutils.create_dummy_dispatcher()

    test_path = 'test_module_dir'
    test_mod_path = os.path.join(test_path, 'test_module.py')

    os.mkdir(test_path)
    with open(test_mod_path, 'w') as f:
        f.write('CONSTANT = "This module was imported!"')

    if (sys.argv[1] == 'success'):
        await disp._handle__function_environment_reload_request(request_msg)

    try:
        import test_module
        print(test_module.CONSTANT)
    finally:
        # Cleanup
        shutil.rmtree(test_path)
    async def test_handles_unsupported_messages_gracefully(self):
        async with testutils.start_mockhost() as host:
            # Intentionally send a message to worker that isn't
            # going to be ever supported by it.  The idea is that
            # workers should survive such messages and continue
            # their operation.  If anything, the host can always
            # terminate the worker.
            await host.send(
                protos.StreamingMessage(
                    worker_heartbeat=protos.WorkerHeartbeat()))

            _, r = await host.load_function('return_out')
            self.assertEqual(r.response.result.status,
                             protos.StatusResult.Success)
Пример #3
0
    async def _verify_environment_reloaded(self, test_env):
            request = protos.FunctionEnvironmentReloadRequest(
                environment_variables=test_env)

            request_msg = protos.StreamingMessage(
                request_id='0',
                function_environment_reload_request=request)

            disp = testutils.create_dummy_dispatcher()

            try:
                r = await disp._handle__function_environment_reload_request(
                    request_msg)

                environ_dict = os.environ.copy()
                self.assertDictEqual(environ_dict, test_env)
                status = r.function_environment_reload_response.result.status
                self.assertEqual(status, protos.StatusResult.Success)
            finally:
                self._reset_environ()
Пример #4
0
    async def _handle_environment_reload_request(self, test_env):
        request = protos.FunctionEnvironmentReloadRequest(
            environment_variables=test_env)

        request_msg = protos.StreamingMessage(
            request_id='0', function_environment_reload_request=request)

        dummy_event_loop = asyncio.new_event_loop()
        disp = dispatcher.Dispatcher(dummy_event_loop, '127.0.0.1', 0,
                                     'test_worker_id', 'test_request_id', 1.0,
                                     1000)
        dummy_event_loop.close()

        try:
            r = await disp._handle__function_environment_reload_request(
                request_msg)

            environ_dict = os.environ.copy()
            self.assertDictEqual(environ_dict, test_env)
            status = r.function_environment_reload_response.result.status
            self.assertEqual(status, protos.StatusResult.Success)
        finally:
            self.reset_environ()