public async Task CreateChannels_Succeeds()
        {
            string            language          = RpcWorkerConstants.JavaLanguageWorkerName;
            IRpcWorkerChannel javaWorkerChannel = CreateTestChannel(language);
            var initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(language);

            IRpcWorkerChannel javaWorkerChannel2 = CreateTestChannel(RpcWorkerConstants.JavaLanguageWorkerName);

            Assert.NotNull(initializedChannel);
            Assert.Equal(javaWorkerChannel.Id, initializedChannel.Id);
            Assert.Equal(_rpcWorkerChannelManager.GetChannels(RpcWorkerConstants.JavaLanguageWorkerName).Count(), 2);
        }
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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 ShutdownStandByChannels_WorkerRuntinmeDotNet_Succeeds()
        {
            var testMetricsLogger = new TestMetricsLogger();

            _testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, RpcWorkerConstants.DotNetLanguageWorkerName);
            _rpcWorkerChannelManager = new WebHostRpcWorkerChannelManager(_eventManager, _testEnvironment, _loggerFactory, _rpcWorkerChannelFactory, _optionsMonitor, testMetricsLogger);

            IRpcWorkerChannel javaWorkerChannel = CreateTestChannel(RpcWorkerConstants.JavaLanguageWorkerName);
            IRpcWorkerChannel nodeWorkerChannel = CreateTestChannel(RpcWorkerConstants.NodeLanguageWorkerName);

            _rpcWorkerChannelManager.ScheduleShutdownStandbyChannels();
            Assert.True(AreRequiredMetricsEmitted(testMetricsLogger));
            IRpcWorkerChannel initializedChannel = await _rpcWorkerChannelManager.GetChannelAsync(RpcWorkerConstants.NodeLanguageWorkerName);

            Assert.Null(initializedChannel);
            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);
        }