Example #1
0
        public async void FunctionDispatcherState_Default_DotNetFunctions()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "dotnet"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);

            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);

            await functionDispatcher.InitializeAsync(functions);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
        }
Example #2
0
        public async void FunctionDispatcherState_Default_NoFunctions()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            await functionDispatcher.InitializeAsync(new List <FunctionMetadata>());
        }
        public async Task FunctionDispatcher_ShouldRestartChannel_Returns_True(string language, bool isWebHostChannel, bool isJobHostChannel, bool expectedResult)
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            Assert.Equal(expectedResult, functionDispatcher.ShouldRestartWorkerChannel(language, isWebHostChannel, isJobHostChannel));
        }
        public async Task FunctionDispatcher_ErroredWebHostChannel()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher(throwOnProcessStartUp: true, addWebhostChannel: true);
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.JavaLanguageWorkerName));

            var testLogs = _testLogger.GetLogMessages();

            Assert.False(testLogs.Any(m => m.FormattedMessage.Contains("Removing errored webhost language worker channel for runtime")));
        }
Example #5
0
        public async void Starting_MultipleJobhostChannels_Succeeds()
        {
            int expectedProcessCount = 3;
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher(expectedProcessCount.ToString());
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            var finalChannelCount = await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            Assert.Equal(expectedProcessCount, finalChannelCount);
        }
Example #6
0
        public async void Starting_MultipleJobhostChannels_Succeeds()
        {
            int expectedProcessCount = 3;
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(expectedProcessCount.ToString());
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            var finalChannelCount = await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            Assert.Equal(finalChannelCount, expectedProcessCount);

            // Verify LanguageWorkerChannelState when channel after it is initialized
            Assert.True(functionDispatcher.WorkerState.GetChannels().All(ch => ch.State == LanguageWorkerChannelState.Initialized));
        }
Example #7
0
        public async void ShutdownChannels_NoFunctions()
        {
            var mockLanguageWorkerChannelManager  = new Mock <ILanguageWorkerChannelManager>();
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(mockLanguageWorkerChannelManager: mockLanguageWorkerChannelManager);

            Assert.Equal(functionDispatcher.State, FunctionDispatcherState.Default);
            await functionDispatcher.InitializeAsync(new List <FunctionMetadata>());

            // Wait longer than debouce action.
            await Task.Delay(6000);

            mockLanguageWorkerChannelManager.Verify(m => m.ShutdownChannels(), Times.Once);
        }
Example #8
0
        public async void Starting_MultipleWebhostChannels_Succeeds()
        {
            int expectedProcessCount = 2;
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher(expectedProcessCount.ToString(), true);
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.JavaLanguageWorkerName));

            var finalWebhostChannelCount = await WaitForWebhostWorkerChannelsToStartup(functionDispatcher.WebHostLanguageWorkerChannelManager, expectedProcessCount, "java");

            Assert.Equal(expectedProcessCount, finalWebhostChannelCount);

            var finalJobhostChannelCount = functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Count();

            Assert.Equal(0, finalJobhostChannelCount);
        }
        public async Task FunctionDispatcher_DoNot_Restart_ErroredChannels_If_WorkerRuntime_DoesNotMatch()
        {
            int expectedProcessCount = 1;
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(expectedProcessCount.ToString());
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            _javaTestChannel.RaiseWorkerError();
            var testLogs = _testLogger.GetLogMessages();

            Assert.False(testLogs.Any(m => m.FormattedMessage.Contains("Restarting worker channel for runtime:java")));
            Assert.Equal(expectedProcessCount, functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Count());
        }
        public async Task ShutdownChannels_NoFunctions()
        {
            var mockLanguageWorkerChannelManager = new Mock <IWebHostLanguageWorkerChannelManager>();

            mockLanguageWorkerChannelManager.Setup(m => m.ShutdownChannelsAsync()).Returns(Task.CompletedTask);
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockLanguageWorkerChannelManager);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            await functionDispatcher.InitializeAsync(new List <FunctionMetadata>());

            // Wait longer than debouce action.
            await Task.Delay(6000);

            mockLanguageWorkerChannelManager.Verify(m => m.ShutdownChannelsAsync(), Times.Once);
        }
Example #11
0
        public async void FunctionDispatcherState_Transitions_From_Starting_To_Initialized()
        {
            FunctionDispatcher functionDispatcher = GetTestFunctionDispatcher();
            FunctionMetadata   func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "node"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            await functionDispatcher.InitializeAsync(functions);

            Assert.True(functionDispatcher.State == FunctionDispatcherState.Initializing || functionDispatcher.State == FunctionDispatcherState.Initialized);
            await WaitForFunctionDispactherStateInitialized(functionDispatcher);
        }
Example #12
0
        public async void FunctionDispatcher_Restart_ErroredChannels_ExcceedsLimit()
        {
            int expectedProcessCount = 2;
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(expectedProcessCount.ToString());
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            for (int restartCount = 0; restartCount < expectedProcessCount * 3; restartCount++)
            {
                foreach (var channel in functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels())
                {
                    TestLanguageWorkerChannel testWorkerChannel = channel as TestLanguageWorkerChannel;
                    testWorkerChannel.RaiseWorkerError();
                }
            }
            Assert.Equal(0, functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().Count());
        }
        public async Task FunctionDispatcher_Error_BeyondThreshold_BucketIsAtOne()
        {
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher("1");
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, 1);

            for (int i = 1; i < 10; ++i)
            {
                foreach (var channel in functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels())
                {
                    TestLanguageWorkerChannel testWorkerChannel = channel as TestLanguageWorkerChannel;
                    testWorkerChannel.RaiseWorkerErrorWithCustomTimestamp(DateTime.UtcNow.AddHours(i));
                }
            }

            Assert.Equal(1, functionDispatcher.LanguageWorkerErrors.Count);
        }
        public async Task FunctionDispatcher_Error_WithinThreshold_BucketFills()
        {
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher("1");
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, 1);

            for (int i = 0; i < 3; ++i)
            {
                foreach (var channel in functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels())
                {
                    TestLanguageWorkerChannel testWorkerChannel = channel as TestLanguageWorkerChannel;
                    testWorkerChannel.RaiseWorkerError();
                }
            }

            Assert.Equal(3, functionDispatcher.LanguageWorkerErrors.Count);
        }
Example #15
0
        public async void FunctionDispatcher_Restart_ErroredChannels_Succeeds()
        {
            int expectedProcessCount = 2;
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(expectedProcessCount.ToString());
            await functionDispatcher.InitializeAsync(GetTestFunctionsList(LanguageWorkerConstants.NodeLanguageWorkerName));

            await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);

            int finalChannelCount = 0;

            for (int restartCount = 0; restartCount < expectedProcessCount * 3; restartCount++)
            {
                TestLanguageWorkerChannel testWorkerChannel = (TestLanguageWorkerChannel)functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels().FirstOrDefault();
                if (functionDispatcher.LanguageWorkerErrors.Count < (expectedProcessCount * 3) - 1)
                {
                    testWorkerChannel.RaiseWorkerError();
                }
                finalChannelCount = await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount);
            }
            Assert.Equal(expectedProcessCount, finalChannelCount);
        }
Example #16
0
        public async void ShutdownChannels_DotNetFunctions()
        {
            FunctionMetadata func1 = new FunctionMetadata()
            {
                Name     = "func1",
                Language = "dotnet"
            };
            var functions = new List <FunctionMetadata>()
            {
                func1
            };
            var mockLanguageWorkerChannelManager  = new Mock <IWebHostLanguageWorkerChannelManager>();
            FunctionDispatcher functionDispatcher = (FunctionDispatcher)GetTestFunctionDispatcher(mockwebHostLanguageWorkerChannelManager: mockLanguageWorkerChannelManager);

            Assert.Equal(FunctionDispatcherState.Default, functionDispatcher.State);
            await functionDispatcher.InitializeAsync(functions);

            // Wait longer than debouce action.
            await Task.Delay(6000);

            mockLanguageWorkerChannelManager.Verify(m => m.ShutdownChannels(), Times.Once);
        }