public async Task InitializeLanguageWorkerChannel_ThrowsOnProcessStartup()
        {
            var languageWorkerChannelFactory = new TestLanguageWorkerChannelFactory(_eventManager, null, _scriptRootPath, throwOnProcessStartUp: true);
            var languageWorkerChannelManager = new WebHostLanguageWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, languageWorkerChannelFactory, _optionsMonitor);
            var languageWorkerChannel        = await languageWorkerChannelManager.InitializeLanguageWorkerChannel("test", _scriptRootPath);

            var ex = await Assert.ThrowsAsync <AggregateException>(async() => await languageWorkerChannelManager.GetChannelAsync("test"));

            Assert.Contains("Process startup failed", ex.InnerException.Message);
        }
        private static FunctionDispatcher GetTestFunctionDispatcher(string maxProcessCountValue = null, bool addWebhostChannel = false, Mock <IWebHostLanguageWorkerChannelManager> mockwebHostLanguageWorkerChannelManager = null)
        {
            var eventManager             = new ScriptEventManager();
            var scriptJobHostEnvironment = new Mock <IScriptJobHostEnvironment>();
            var metricsLogger            = new Mock <IMetricsLogger>();
            var testEnv = new TestEnvironment();

            if (!string.IsNullOrEmpty(maxProcessCountValue))
            {
                testEnv.SetEnvironmentVariable(LanguageWorkerConstants.FunctionsWorkerProcessCountSettingName, maxProcessCountValue);
            }

            var loggerFactory = MockNullLoggerFactory.CreateLoggerFactory();

            var options = new ScriptJobHostOptions
            {
                RootLogPath = Path.GetTempPath()
            };

            IOptions <ScriptJobHostOptions> scriptOptions = new OptionsManager <ScriptJobHostOptions>(new TestOptionsFactory <ScriptJobHostOptions>(options));

            var workerConfigOptions = new LanguageWorkerOptions
            {
                WorkerConfigs = TestHelpers.GetTestWorkerConfigs()
            };
            IWebHostLanguageWorkerChannelManager testWebHostLanguageWorkerChannelManager = new TestLanguageWorkerChannelManager(eventManager, _testLogger, scriptOptions.Value.RootScriptPath);
            ILanguageWorkerChannelFactory        testLanguageWorkerChannelFactory        = new TestLanguageWorkerChannelFactory(eventManager, _testLogger, scriptOptions.Value.RootScriptPath);
            IJobHostLanguageWorkerChannelManager jobHostLanguageWorkerChannelManager     = new JobHostLanguageWorkerChannelManager(loggerFactory);

            if (addWebhostChannel)
            {
                testWebHostLanguageWorkerChannelManager.InitializeChannelAsync("java");
            }
            if (mockwebHostLanguageWorkerChannelManager != null)
            {
                testWebHostLanguageWorkerChannelManager = mockwebHostLanguageWorkerChannelManager.Object;
            }
            var mockFunctionDispatcherLoadBalancer = new Mock <IFunctionDispatcherLoadBalancer>();

            _javaTestChannel = new TestLanguageWorkerChannel(Guid.NewGuid().ToString(), "java", eventManager, _testLogger, false);

            return(new FunctionDispatcher(scriptOptions,
                                          metricsLogger.Object,
                                          testEnv,
                                          scriptJobHostEnvironment.Object,
                                          eventManager,
                                          loggerFactory,
                                          testLanguageWorkerChannelFactory,
                                          new OptionsWrapper <LanguageWorkerOptions>(workerConfigOptions),
                                          testWebHostLanguageWorkerChannelManager,
                                          jobHostLanguageWorkerChannelManager,
                                          null,
                                          mockFunctionDispatcherLoadBalancer.Object));
        }