예제 #1
0
        /// <summary>
        /// Initializes the UserCodeLoader using the Function Handler and runs LambdaBootstrap asynchronously.
        /// </summary>
        public async Task RunLambdaBootstrap()
        {
            await _debugAttacher.TryAttachDebugger();

            var userCodeLoader = new UserCodeLoader(_handler, _logger);
            var initializer    = new UserCodeInitializer(userCodeLoader, _logger);

            using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(userCodeLoader.Invoke))
                using (var bootstrap = new LambdaBootstrap(handlerWrapper, initializer.InitializeAsync))
                {
                    await bootstrap.RunAsync();
                }
        }
예제 #2
0
        private async Task <Exception> TestHandlerFailAsync(string handler, string expectedPartialMessage, bool?expectAggregateException = null)
        {
            _output.WriteLine($"Testing handler {handler}");

            var testRuntimeApiClient = new TestRuntimeApiClient(_environmentVariables, _headers);

            var userCodeLoader = new UserCodeLoader(handler, _internalLogger);
            var initializer    = new UserCodeInitializer(userCodeLoader, _internalLogger);
            var handlerWrapper = HandlerWrapper.GetHandlerWrapper(userCodeLoader.Invoke);
            var bootstrap      = new LambdaBootstrap(handlerWrapper, initializer.InitializeAsync)
            {
                Client = testRuntimeApiClient
            };

            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                var exceptionWaiterTask = Task.Run(() =>
                {
                    _output.WriteLine($"Waiting for an exception.");
                    while (testRuntimeApiClient.LastRecordedException == null)
                    {
                    }
                    _output.WriteLine($"Exception available.");
                    cancellationTokenSource.Cancel();
                    return(testRuntimeApiClient.LastRecordedException);
                });

                await Record.ExceptionAsync(async() =>
                {
                    await bootstrap.RunAsync(cancellationTokenSource.Token);
                });

                var exception = await exceptionWaiterTask;
                Assert.NotNull(exception);

                Common.CheckException(exception, expectedPartialMessage);
                Common.CheckForAggregateException(exception, expectAggregateException);
                return(exception);
            }
        }
예제 #3
0
        private async Task <ExecutionInfo> ExecHandlerAsync(string handler, string dataIn, string assertLoggedByInitialize)
        {
            // The actionWriter
            using (var actionWriter = new StringWriter())
            {
                var testRuntimeApiClient = new TestRuntimeApiClient(_environmentVariables, _headers);
                var loggerAction         = actionWriter.ToLoggingAction();
                var assembly             = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(UserCodeLoader.LambdaCoreAssemblyName));
                UserCodeLoader.SetCustomerLoggerLogAction(assembly, loggerAction, _internalLogger);

                var userCodeLoader = new UserCodeLoader(handler, _internalLogger);
                var handlerWrapper = HandlerWrapper.GetHandlerWrapper(userCodeLoader.Invoke);
                var initializer    = new UserCodeInitializer(userCodeLoader, _internalLogger);
                var bootstrap      = new LambdaBootstrap(handlerWrapper, initializer.InitializeAsync)
                {
                    Client = testRuntimeApiClient
                };

                if (assertLoggedByInitialize != null)
                {
                    Assert.False(actionWriter.ToString().Contains($"^^[{assertLoggedByInitialize}]^^"));
                }

                await bootstrap.InitializeAsync();

                if (assertLoggedByInitialize != null)
                {
                    Assert.True(actionWriter.ToString().Contains($"^^[{assertLoggedByInitialize}]^^"));
                }

                var dataOut = await InvokeAsync(bootstrap, dataIn, testRuntimeApiClient);

                var actionText = actionWriter.ToString();

                return(new ExecutionInfo(bootstrap, dataIn, dataOut, actionText, null, userCodeLoader));
            }
        }