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 #2
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 #3
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 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);
        }