|
7 | 7 | using System.Collections.ObjectModel;
|
8 | 8 | using System.IO;
|
9 | 9 | using System.Linq;
|
| 10 | +using System.Threading; |
10 | 11 | using System.Threading.Tasks;
|
11 | 12 | using Microsoft.Azure.WebJobs.Script.Description;
|
12 | 13 | using Microsoft.Azure.WebJobs.Script.Workers.Http;
|
@@ -222,6 +223,34 @@ public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProv
|
222 | 223 | Assert.DoesNotContain(traces, t => t.FormattedMessage.Contains("2 functions found (Custom)"));
|
223 | 224 | }
|
224 | 225 |
|
| 226 | + [Fact] |
| 227 | + public void FunctionMetadataManager_LoadFunctionMetadata_BadMetadataProvider_ReturnsFailedTask() |
| 228 | + { |
| 229 | + var functionMetadataCollection = new Collection<FunctionMetadata>(); |
| 230 | + var mockFunctionErrors = new Dictionary<string, ImmutableArray<string>>(); |
| 231 | + var mockFunctionMetadataProvider = new Mock<IFunctionMetadataProvider>(); |
| 232 | + var badFunctionMetadataProvider = new Mock<IFunctionProvider>(); |
| 233 | + var workerConfigs = TestHelpers.GetTestWorkerConfigs(); |
| 234 | + var testLoggerProvider = new TestLoggerProvider(); |
| 235 | + var loggerFactory = new LoggerFactory(); |
| 236 | + loggerFactory.AddProvider(testLoggerProvider); |
| 237 | + |
| 238 | + mockFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, SystemEnvironment.Instance, false)).Returns(Task.FromResult(new Collection<FunctionMetadata>().ToImmutableArray())); |
| 239 | + mockFunctionMetadataProvider.Setup(m => m.FunctionErrors).Returns(new Dictionary<string, ICollection<string>>().ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.ToImmutableArray())); |
| 240 | + |
| 241 | + // A bad provider that returns a faulty task |
| 242 | + var tcs = new TaskCompletionSource<ImmutableArray<FunctionMetadata>>(); |
| 243 | + badFunctionMetadataProvider |
| 244 | + .Setup(m => m.GetFunctionMetadataAsync()) |
| 245 | + .Returns(Task.FromException<ImmutableArray<FunctionMetadata>>(new Exception("Simulated failure"))); |
| 246 | + |
| 247 | + FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(new OptionsWrapper<ScriptJobHostOptions>(_scriptJobHostOptions), |
| 248 | + mockFunctionMetadataProvider.Object, new List<IFunctionProvider>() { badFunctionMetadataProvider.Object }, new OptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions), loggerFactory, new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions())); |
| 249 | + |
| 250 | + var exception = Assert.Throws<AggregateException>(() => testFunctionMetadataManager.LoadFunctionMetadata()); |
| 251 | + Assert.Contains("Simulated failure", exception.InnerException.Message); |
| 252 | + } |
| 253 | + |
225 | 254 | [Fact]
|
226 | 255 | public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProvidersTimesOut()
|
227 | 256 | {
|
|
0 commit comments