From 8ae4c4de5993fe8f9deb01082db0756b30e01819 Mon Sep 17 00:00:00 2001 From: Lilian Kasem Date: Mon, 4 Nov 2024 15:56:04 -0800 Subject: [PATCH 1/3] Return metadata provider task whether it is successful or not --- src/WebJobs.Script/Host/FunctionMetadataManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebJobs.Script/Host/FunctionMetadataManager.cs b/src/WebJobs.Script/Host/FunctionMetadataManager.cs index 99f4169518..98ea2d789a 100644 --- a/src/WebJobs.Script/Host/FunctionMetadataManager.cs +++ b/src/WebJobs.Script/Host/FunctionMetadataManager.cs @@ -236,7 +236,7 @@ private void AddMetadataFromCustomProviders(IEnumerable funct var completedTask = Task.WhenAny(getFunctionMetadataFromProviderTask, delayTask).ContinueWith(t => { - if (t.Result == getFunctionMetadataFromProviderTask && getFunctionMetadataFromProviderTask.IsCompletedSuccessfully) + if (t.Result == getFunctionMetadataFromProviderTask) { return getFunctionMetadataFromProviderTask.Result; } From 2a0036295f1d61a01d8c57543d82d6980f15dc8f Mon Sep 17 00:00:00 2001 From: Lilian Kasem Date: Mon, 4 Nov 2024 17:21:30 -0800 Subject: [PATCH 2/3] Add test --- .../FunctionMetadataManagerTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs b/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs index 04a5187cb0..9370995c1d 100644 --- a/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs +++ b/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs @@ -222,6 +222,35 @@ public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProv Assert.DoesNotContain(traces, t => t.FormattedMessage.Contains("2 functions found (Custom)")); } + [Fact] + public void FunctionMetadataManager_LoadFunctionMetadata_BadMetadataProvider_ReturnsFailedTask() + { + var functionMetadataCollection = new Collection(); + var mockFunctionErrors = new Dictionary>(); + var mockFunctionMetadataProvider = new Mock(); + var badFunctionMetadataProvider = new Mock(); + var workerConfigs = TestHelpers.GetTestWorkerConfigs(); + var testLoggerProvider = new TestLoggerProvider(); + var loggerFactory = new LoggerFactory(); + loggerFactory.AddProvider(testLoggerProvider); + + mockFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, SystemEnvironment.Instance, false)).Returns(Task.FromResult(new Collection().ToImmutableArray())); + mockFunctionMetadataProvider.Setup(m => m.FunctionErrors).Returns(new Dictionary>().ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.ToImmutableArray())); + + // A bad provider that returns a faulty task + var tcs = new TaskCompletionSource>(); + badFunctionMetadataProvider + .Setup(m => m.GetFunctionMetadataAsync()) + .Returns(Task.FromException>(new Exception("Simulated failure"))); + + FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(new OptionsWrapper(_scriptJobHostOptions), + mockFunctionMetadataProvider.Object, new List() { badFunctionMetadataProvider.Object }, new OptionsWrapper(_defaultHttpWorkerOptions), loggerFactory, new TestOptionsMonitor(TestHelpers.GetTestLanguageWorkerOptions())); + + testFunctionMetadataManager.MetadataProviderTimeout = Timeout.InfiniteTimeSpan; + var exception = Assert.Throws(() => testFunctionMetadataManager.LoadFunctionMetadata()); + Assert.Contains("Simulated failure", exception.InnerException.Message); + } + [Fact] public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProvidersTimesOut() { From 234df34e857d8c5a620e1e87e68f7908a77fbe07 Mon Sep 17 00:00:00 2001 From: Lilian Kasem Date: Tue, 5 Nov 2024 09:59:50 -0800 Subject: [PATCH 3/3] Update test --- test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs b/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs index 9370995c1d..b8bd98a3c4 100644 --- a/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs +++ b/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs @@ -7,6 +7,7 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Script.Description; using Microsoft.Azure.WebJobs.Script.Workers.Http; @@ -246,7 +247,6 @@ public void FunctionMetadataManager_LoadFunctionMetadata_BadMetadataProvider_Ret FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(new OptionsWrapper(_scriptJobHostOptions), mockFunctionMetadataProvider.Object, new List() { badFunctionMetadataProvider.Object }, new OptionsWrapper(_defaultHttpWorkerOptions), loggerFactory, new TestOptionsMonitor(TestHelpers.GetTestLanguageWorkerOptions())); - testFunctionMetadataManager.MetadataProviderTimeout = Timeout.InfiniteTimeSpan; var exception = Assert.Throws(() => testFunctionMetadataManager.LoadFunctionMetadata()); Assert.Contains("Simulated failure", exception.InnerException.Message); }