예제 #1
0
        public async Task TestLocalRcpEndpointRuntimeVersion(string runtimeVersion, bool enabledExpected)
        {
            INameResolver nameResolver = new SimpleNameResolver(
                new Dictionary <string, string>
            {
                { "FUNCTIONS_WORKER_RUNTIME", runtimeVersion },
            });

            using (ITestHost host = TestHelpers.GetJobHost(
                       this.loggerProvider,
                       nameof(this.TestLocalRcpEndpointRuntimeVersion),
                       enableExtendedSessions: false,
                       localRpcEndpointEnabled: null /* use FUNCTIONS_WORKER_RUNTIME to decide */,
                       nameResolver: nameResolver))
            {
                await host.StartAsync();

                // Check to see whether the local RPC endpoint has been opened
                IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
                IPEndPoint[]       endpoints          = ipGlobalProperties.GetActiveTcpListeners();

                const string LocalRcpAddress = "127.0.0.1:17071";
                if (enabledExpected)
                {
                    Assert.Contains(LocalRcpAddress, endpoints.Select(ep => ep.ToString()));
                }
                else
                {
                    Assert.DoesNotContain(LocalRcpAddress, endpoints.Select(ep => ep.ToString()));
                }

                await host.StopAsync();
            }
        }
        public async Task TestLocalRcpEndpointRuntimeVersion(string runtimeVersion, bool enabledExpected)
        {
            INameResolver nameResolver = new SimpleNameResolver(
                new Dictionary <string, string>
            {
                { "FUNCTIONS_WORKER_RUNTIME", runtimeVersion },
            });

            using (ITestHost host = TestHelpers.GetJobHost(
                       this.loggerProvider,
                       nameof(this.TestLocalRcpEndpointRuntimeVersion),
                       enableExtendedSessions: false,
                       localRpcEndpointEnabled: null /* use FUNCTIONS_WORKER_RUNTIME to decide */,
                       nameResolver: nameResolver))
            {
                await host.StartAsync();

                // Validate if we opened local RPC endpoint by looking at log statements.
                var  logger             = this.loggerProvider.CreatedLoggers.Single(l => l.Category == TestHelpers.LogCategory);
                var  logMessages        = logger.LogMessages.ToList();
                bool enabledRpcEndpoint = logMessages.Any(msg => msg.Level == Microsoft.Extensions.Logging.LogLevel.Information && msg.FormattedMessage.StartsWith("Opened local RPC endpoint:"));

                Assert.Equal(enabledExpected, enabledRpcEndpoint);

                await host.StopAsync();
            }
        }