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; } diff --git a/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs b/test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs index 04a5187cb0..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; @@ -222,6 +223,34 @@ 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())); + + var exception = Assert.Throws(() => testFunctionMetadataManager.LoadFunctionMetadata()); + Assert.Contains("Simulated failure", exception.InnerException.Message); + } + [Fact] public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProvidersTimesOut() {