Skip to content

Commit

Permalink
Update metadata manager tests (#10594)
Browse files Browse the repository at this point in the history
  • Loading branch information
liliankasem authored Nov 4, 2024
1 parent 4c23ea9 commit bfa7535
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/WebJobs.Script/Host/FunctionMetadataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ public FunctionMetadataManager(IOptions<ScriptJobHostOptions> scriptOptions, IFu
}

// Property is settable for testing purposes.
internal int MetadataProviderTimeoutInSeconds { get; set; } = DefaultMetadataProviderTimeoutInSeconds;
internal TimeSpan MetadataProviderTimeout
{
get
{
return _metadataProviderTimeout;
}

set
{
_metadataProviderTimeout = value;
}
}

public ImmutableDictionary<string, ImmutableArray<string>> Errors { get; private set; }

Expand Down
25 changes: 24 additions & 1 deletion test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -223,6 +224,28 @@ public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProv
Assert.DoesNotContain(traces, t => t.FormattedMessage.Contains("2 functions found (Custom)"));
}

[Fact]
public void FunctionMetadataManager_IsLogicApp_TimeoutIsInfinite()
{
using (new TestScopedEnvironmentVariable(EnvironmentSettingNames.AppKind, ScriptConstants.WorkFlowAppKind))
{
var functionMetadataCollection = new Collection<FunctionMetadata>();
var mockFunctionErrors = new Dictionary<string, ImmutableArray<string>>();
var mockFunctionMetadataProvider = new Mock<IFunctionMetadataProvider>();
var mockFunctionProvider = new Mock<IFunctionProvider>();
var workerConfigs = TestHelpers.GetTestWorkerConfigs();
var testLoggerProvider = new TestLoggerProvider();
var loggerFactory = new LoggerFactory();
loggerFactory.AddProvider(testLoggerProvider);

FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(new OptionsWrapper<ScriptJobHostOptions>(_scriptJobHostOptions),
mockFunctionMetadataProvider.Object, new List<IFunctionProvider>() { mockFunctionProvider.Object }, new OptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions), loggerFactory,
new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));

Assert.Equal(Timeout.InfiniteTimeSpan, testFunctionMetadataManager.MetadataProviderTimeout);
}
}

[Fact]
public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProvidersTimesOut()
{
Expand Down Expand Up @@ -256,7 +279,7 @@ public void FunctionMetadataManager_LoadFunctionMetadata_Throws_WhenFunctionProv
mockFunctionMetadataProvider.Object, new List<IFunctionProvider>() { goodFunctionMetadataProvider.Object, badFunctionMetadataProvider.Object }, new OptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions), loggerFactory, new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));

// Set the timeout to 1 second for the test.
testFunctionMetadataManager.MetadataProviderTimeoutInSeconds = 1;
testFunctionMetadataManager.MetadataProviderTimeout = TimeSpan.FromSeconds(1);

var exception = Assert.Throws<TimeoutException>(() => testFunctionMetadataManager.LoadFunctionMetadata());
Assert.Contains($"Timeout occurred while retrieving metadata from provider '{badFunctionMetadataProvider.Object.GetType().FullName}'. The operation exceeded the configured timeout of 1 seconds.", exception.Message);
Expand Down

0 comments on commit bfa7535

Please sign in to comment.