public void GetFunctionMetadataAsync_InputMixedApp()
        {
            // Arrange
            _logger.ClearLogMessages();

            IEnumerable <RawFunctionMetadata> rawFunctionMetadataCollection = new List <RawFunctionMetadata>();
            var functionMetadataCollection = new List <FunctionMetadata>();

            functionMetadataCollection.Add(GetTestFunctionMetadata());

            var workerConfigs = TestHelpers.GetTestWorkerConfigs().ToImmutableArray();

            workerConfigs.ToList().ForEach(config => config.Description.WorkerIndexing = "true");
            var scriptjobhostoptions = new ScriptJobHostOptions();

            scriptjobhostoptions.RootScriptPath = Path.Combine(Environment.CurrentDirectory, @"..", "..", "..", "..", "..", "sample", "node");

            var environment = SystemEnvironment.Instance;

            environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "node");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsFeatureFlags, "EnableWorkerIndexing");

            _mockRpcFunctionInvocationDispatcher.Setup(m => m.InitializeAsync(functionMetadataCollection, default)).Returns(Task.FromResult(0));
            _mockRpcFunctionInvocationDispatcher.Setup(m => m.GetWorkerMetadata()).Returns(Task.FromResult(rawFunctionMetadataCollection));

            _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider(
                _logger,
                _mockRpcFunctionInvocationDispatcher.Object,
                _mockFunctionMetadataProvider.Object,
                new OptionsWrapper <ScriptJobHostOptions>(scriptjobhostoptions));

            // Act
            var functions = _aggregateFunctionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, environment, false).GetAwaiter().GetResult();

            // Assert
            string expectedLog = "Detected mixed function app. Some functions may not be indexed";
            var    traces      = _logger.GetLogMessages();

            Assert.False(traces.Where(m => m.FormattedMessage.Contains(expectedLog)).Any());

            Task.Delay(TimeSpan.FromSeconds(65)).Wait();
            traces = _logger.GetLogMessages();
            Assert.True(traces.Where(m => m.FormattedMessage.Contains(expectedLog)).Any());
        }
        public void GetFunctionMetadataAsync_WorkerIndexing_HostFallback()
        {
            // Arrange
            _logger.ClearLogMessages();

            var function = GetTestRawFunctionMetadata(useDefaultMetadataIndexing: true);
            IEnumerable <RawFunctionMetadata> rawFunctionMetadataCollection = new List <RawFunctionMetadata>()
            {
                function
            };
            var functionMetadataCollection = new List <FunctionMetadata>();

            functionMetadataCollection.Add(GetTestFunctionMetadata());

            var workerConfigs = TestHelpers.GetTestWorkerConfigs().ToImmutableArray();

            workerConfigs.ToList().ForEach(config => config.Description.WorkerIndexing = "true");
            var scriptjobhostoptions = new ScriptJobHostOptions();

            scriptjobhostoptions.RootScriptPath = Path.Combine(Environment.CurrentDirectory, @"..", "..", "..", "..", "..", "sample", "node");

            var environment = SystemEnvironment.Instance;

            environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "node");
            environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsFeatureFlags, "EnableWorkerIndexing");

            _mockRpcFunctionInvocationDispatcher.Setup(m => m.InitializeAsync(functionMetadataCollection, default)).Returns(Task.FromResult(0));
            _mockRpcFunctionInvocationDispatcher.Setup(m => m.GetWorkerMetadata()).Returns(Task.FromResult(rawFunctionMetadataCollection));
            _mockRpcFunctionInvocationDispatcher.Setup(m => m.FinishInitialization(functionMetadataCollection, default)).Returns(Task.FromResult(0));
            _mockFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, environment, false)).Returns(Task.FromResult(functionMetadataCollection.ToImmutableArray()));

            _aggregateFunctionMetadataProvider = new AggregateFunctionMetadataProvider(_logger, _mockRpcFunctionInvocationDispatcher.Object, _mockFunctionMetadataProvider.Object, new OptionsWrapper <ScriptJobHostOptions>(scriptjobhostoptions));

            // Act
            var functions = _aggregateFunctionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, environment, false).GetAwaiter().GetResult();

            // Assert
            var traces           = _logger.GetLogMessages();
            var functionLoadLogs = traces.Where(m => string.Equals(m.FormattedMessage, "Fallback to host indexing as worker denied indexing"));

            Assert.True(functionLoadLogs.Any());
        }