public WebHostRpcWorkerChannelManagerTests() { _eventManager = new ScriptEventManager(); _rpcServer = new TestRpcServer(); _loggerProvider = new TestLoggerProvider(); _loggerFactory = new LoggerFactory(); _testEnvironment = new TestEnvironment(); _loggerFactory.AddProvider(_loggerProvider); _rpcWorkerProcess = new Mock <IWorkerProcess>(); _languageWorkerOptions = new LanguageWorkerOptions { WorkerConfigs = TestHelpers.GetTestWorkerConfigs() }; var applicationHostOptions = new ScriptApplicationHostOptions { IsSelfHost = true, ScriptPath = @"c:\testing\FUNCTIONS-TEST\test$#" }; _optionsMonitor = TestHelpers.CreateOptionsMonitor(applicationHostOptions); _rpcWorkerProcessFactory = new Mock <IRpcWorkerProcessFactory>(); _rpcWorkerProcessFactory.Setup(m => m.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(_rpcWorkerProcess.Object); _testLogger = new TestLogger("WebHostLanguageWorkerChannelManagerTests"); _rpcWorkerChannelFactory = new TestRpcWorkerChannelFactory(_eventManager, _testLogger, _scriptRootPath); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, new TestMetricsLogger()); }
public async Task SpecializeAsync_Java_ReadOnly_KeepsProcessAlive() { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, RpcWorkerConstants.JavaLanguageWorkerName); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteZipDeployment, "1"); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger); IRpcWorkerChannel javaWorkerChannel = CreateTestChannel(RpcWorkerConstants.JavaLanguageWorkerName); await _rpcWorkerChannelManager.SpecializeAsync(); Assert.True(testMetricsLogger.EventsBegan.Contains(MetricEventNames.SpecializationScheduleShutdownStandbyChannels) && testMetricsLogger.EventsEnded.Contains(MetricEventNames.SpecializationScheduleShutdownStandbyChannels)); // Verify logs var traces = _testLogger.GetLogMessages(); var functionLoadLogs = traces.Where(m => string.Equals(m.FormattedMessage, "SendFunctionEnvironmentReloadRequest called")); Assert.True(functionLoadLogs.Count() == 1); // Verify channel var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName); Assert.Equal(javaWorkerChannel, initializedChannel); }
public async Task SpecializeAsync_LanguageWorkerArguments_KillsProcess(string languageWorkerName, string argument) { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, languageWorkerName); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion, "~3"); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteZipDeployment, "1"); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { [$"{RpcWorkerConstants.LanguageWorkersSectionName}:{languageWorkerName}:{WorkerConstants.WorkerDescriptionArguments}"] = argument }) .Build(); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger, _workerOptionsMonitor, config); IRpcWorkerChannel workerChannel = CreateTestChannel(languageWorkerName); await _rpcWorkerChannelManager.SpecializeAsync(); // Verify logs var traces = _testLogger.GetLogMessages(); Assert.True(traces.Count() == 0); // Verify channel var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(languageWorkerName); Assert.Null(initializedChannel); }
public async Task SpecializeAsync_ReadOnly_KeepsProcessAlive(string runtime, string languageWorkerName) { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, runtime); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteZipDeployment, "1"); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger, _workerOptionsMonitor, _emptyConfig); IRpcWorkerChannel workerChannel = CreateTestChannel(languageWorkerName); await _rpcWorkerChannelManager.SpecializeAsync(); // Wait for debouce task to start await TestHelpers.Await(() => { return(testMetricsLogger.EventsBegan.Contains(MetricEventNames.SpecializationScheduleShutdownStandbyChannels) && testMetricsLogger.EventsEnded.Contains(MetricEventNames.SpecializationScheduleShutdownStandbyChannels)); }, pollingInterval : 500); // Verify logs var traces = _testLogger.GetLogMessages(); var functionLoadLogs = traces.Where(m => string.Equals(m.FormattedMessage, "SendFunctionEnvironmentReloadRequest called")); Assert.True(functionLoadLogs.Count() == 1); // Verify channel var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(languageWorkerName); Assert.Equal(workerChannel, initializedChannel); }
public async Task InitializeLanguageWorkerChannel_ThrowsOnProcessStartup() { var rpcWorkerChannelFactory = new TestRpcWorkerChannelFactory(_eventManager, null, _scriptRootPath, throwOnProcessStartUp: true); var rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, rpcWorkerChannelFactory, _optionsMonitor, new TestMetricsLogger()); var rpcWorkerChannel = await rpcWorkerChannelManager.InitializeLanguageWorkerChannel("test", _scriptRootPath); var ex = await Assert.ThrowsAsync <AggregateException>(async() => await rpcWorkerChannelManager.GetChannelAsync("test")); Assert.Contains("Process startup failed", ex.InnerException.Message); }
public async Task ShutdownStandyChannels_WorkerRuntime_Node_Set() { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, RpcWorkerConstants.NodeLanguageWorkerName); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger); IRpcWorkerChannel javaWorkerChannel = CreateTestChannel(RpcWorkerConstants.JavaLanguageWorkerName); _rpcWorkerChannelManager.ScheduleShutdownStandbyChannels(); Assert.True(AreRequiredMetricsEmitted(testMetricsLogger)); var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(RpcWorkerConstants.JavaLanguageWorkerName); Assert.Null(initializedChannel); }
public async Task SpecializeAsync_Node_NotReadOnly_KillsProcess() { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, RpcWorkerConstants.NodeLanguageWorkerName); // This is an invalid setting configuration, but just to show that run from zip is NOT set _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteZipDeployment, "0"); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger); IRpcWorkerChannel nodeWorkerChannel = CreateTestChannel(RpcWorkerConstants.NodeLanguageWorkerName); await _rpcWorkerChannelManager.SpecializeAsync(); // Verify logs var traces = _testLogger.GetLogMessages(); Assert.True(traces.Count() == 0); // Verify channel var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName); Assert.Null(initializedChannel); }
public async Task SpecializeAsync_Node_V2CompatibilityWithV3Extension_KillsProcess(string languageWorkerName) { var testMetricsLogger = new TestMetricsLogger(); _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, languageWorkerName); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsV2CompatibilityModeKey, "true"); _testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion, "~3"); _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger, _workerOptionsMonitor); IRpcWorkerChannel workerChannel = CreateTestChannel(languageWorkerName); await _rpcWorkerChannelManager.SpecializeAsync(); // Verify logs var traces = _testLogger.GetLogMessages(); Assert.True(traces.Count() == 0); // Verify channel var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(languageWorkerName); Assert.Null(initializedChannel); }