Skip to content

Commit

Permalink
Fixed incorrect function count in the log message.(#10220)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyju committed Jun 14, 2024
1 parent f138d7c commit 6f52a34
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
- Ensuring proxies are disabled, with a warning, when running in Flex Consumption.
- Fixed an issue leading to a race when invocation responses returned prior to HTTP requests being sent in proxied scenarios.
- Language worker channels will not be started during placeholder mode if we are in-process (#10161)
- Ordered invocations are now the default (#10201)
- Ordered invocations are now the default (#10201)
- Fixed incorrect function count in the log message.(#10220)
3 changes: 2 additions & 1 deletion src/WebJobs.Script/Host/FunctionMetadataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ private void AddMetadataFromCustomProviders(IEnumerable<IFunctionProvider> funct
}

var functionMetadataListArray = Task.WhenAll(functionProviderTasks).GetAwaiter().GetResult();
var totalFunctionsCount = functionMetadataListArray.Sum(metadataArray => metadataArray.Length);

// This is used to make sure no duplicates are registered
var distinctFunctionNames = new HashSet<string>(functionMetadataList.Select(m => m.Name));

_logger.FunctionsReturnedByProvider(functionMetadataListArray.Length, _metadataProviderName);
_logger.FunctionsReturnedByProvider(totalFunctionsCount, _metadataProviderName);

foreach (var metadataArray in functionMetadataListArray)
{
Expand Down
49 changes: 49 additions & 0 deletions test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,55 @@ public void FunctionMetadataManager_DoesNotError_MissingScriptFile_InWebHostMode
Assert.False(testFunctionMetadataManager.IsScriptFileDetermined(testMetadata));
}

[Fact]
public void FunctionMetadataManager_GetsMetadata_FromMultipleFunctionProviders_Success()
{
var functionMetadataCollection1 = new Collection<FunctionMetadata>
{
GetTestFunctionMetadata("somefile.dll", name: "HelloHttp")
};

var functionMetadataCollection2 = new Collection<FunctionMetadata>
{
GetTestFunctionMetadata("somefile2.dll", name: "Function1"),
GetTestFunctionMetadata("somefile2.dll", name: "Function2"),
GetTestFunctionMetadata("somefile2.dll", name: "Function3")
};

var expectedTotalFunctionsCount = functionMetadataCollection1.Count + functionMetadataCollection2.Count;

var mockFunctionMetadataProvider = new Mock<IFunctionMetadataProvider>();
mockFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), It.IsAny<SystemEnvironment>(), It.IsAny<bool>()))
.Returns(Task.FromResult(new Collection<FunctionMetadata>().ToImmutableArray()));
mockFunctionMetadataProvider.Setup(m => m.FunctionErrors)
.Returns(new Dictionary<string, ICollection<string>>().ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.ToImmutableArray()));

var mockFunctionProvider = new Mock<IFunctionProvider>();
mockFunctionProvider.Setup(m => m.GetFunctionMetadataAsync()).ReturnsAsync(functionMetadataCollection1.ToImmutableArray());

var mockFunctionProvider2 = new Mock<IFunctionProvider>();
mockFunctionProvider2.Setup(m => m.GetFunctionMetadataAsync()).ReturnsAsync(functionMetadataCollection2.ToImmutableArray());

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, mockFunctionProvider2.Object },
new OptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions),
loggerFactory,
new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));

var actualFunctionMetadata = testFunctionMetadataManager.LoadFunctionMetadata();

var traces = testLoggerProvider.GetAllLogMessages();
Assert.Equal(expectedTotalFunctionsCount, actualFunctionMetadata.Length);
Assert.Single(traces.Where(t => t.FormattedMessage.Contains("Reading functions metadata (Custom)")));
Assert.Single(traces.Where(t => t.FormattedMessage.Contains($"{expectedTotalFunctionsCount} functions found (Custom)")));
}

[Fact]
public void FunctionMetadataManager_GetsMetadata_FromFunctionProviders()
{
Expand Down

0 comments on commit 6f52a34

Please sign in to comment.