Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check for dotnet-isolated app with extension bundle configured #9466

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
}
}

bool isDotnetApp = isPrecompiledFunctionApp || IsDotnetIsolatedApp(workerConfigs);
surgupta-msft marked this conversation as resolved.
Show resolved Hide resolved

if (SystemEnvironment.Instance.IsPlaceholderModeEnabled())
{
// Do not move this.
Expand All @@ -112,7 +114,7 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()

string baseProbingPath = null;

if (bundleConfigured && (!isPrecompiledFunctionApp || isLegacyExtensionBundle))
if (bundleConfigured && (!isDotnetApp || isLegacyExtensionBundle))
{
extensionsMetadataPath = await _extensionBundleManager.GetExtensionBundleBinPathAsync();
if (string.IsNullOrEmpty(extensionsMetadataPath))
Expand Down Expand Up @@ -331,6 +333,16 @@ void CollectError(Type extensionType, Version minimumVersion, ExtensionStartupTy
}
}

private bool IsDotnetIsolatedApp(IList<RpcWorkerConfig> workerConfigs)
{
if (workerConfigs != null)
{
return workerConfigs.Where(config => config.Description is not null && config.Description.Language == RpcWorkerConstants.DotNetIsolatedLanguageWorkerName).Any();
}

return false;
}

private class TypeNameEqualityComparer : IEqualityComparer<Type>
{
public bool Equals(Type x, Type y)
Expand Down
44 changes: 44 additions & 0 deletions test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,50 @@ public async Task GetExtensionsStartupTypes_LegacyBundles_UsesExtensionBundleBin
}
}

[Fact]
public async Task GetExtensionsStartupTypes_DotnetIsolated_ExtensionBundleConfigured()
{
using (var directory = GetTempDirectory())
{
var binPath = Path.Combine(directory.Path, "bin");
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
TestLoggerProvider testLoggerProvider = new TestLoggerProvider();
LoggerFactory factory = new LoggerFactory();
factory.AddProvider(testLoggerProvider);
var testLogger = factory.CreateLogger<ScriptStartupTypeLocator>();

var mockExtensionBundleManager = new Mock<IExtensionBundleManager>();
mockExtensionBundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true);
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).Returns(Task.FromResult(binPath));
mockExtensionBundleManager.Setup(e => e.IsLegacyExtensionBundle()).Returns(false);
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleDetails()).Returns(Task.FromResult(GetV2BundleDetails()));

RpcWorkerConfig workerConfig = new RpcWorkerConfig() { Description = TestHelpers.GetTestWorkerDescription("dotnet-isolated", "none", true) };
var tempOptions = new LanguageWorkerOptions();
tempOptions.WorkerConfigs = new List<RpcWorkerConfig>();
tempOptions.WorkerConfigs.Add(workerConfig);
var optionsMonitor = new TestOptionsMonitor<LanguageWorkerOptions>(tempOptions);
var mockFunctionMetadataManager = GetTestFunctionMetadataManager(optionsMonitor);

var languageWorkerOptions = new TestOptionsMonitor<LanguageWorkerOptions>(tempOptions);
Environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "dotnet-isolated");

var discoverer = new ScriptStartupTypeLocator(directory.Path, testLogger, mockExtensionBundleManager.Object, mockFunctionMetadataManager, testMetricsLogger, languageWorkerOptions);

// Act
var types = await discoverer.GetExtensionsStartupTypesAsync();

//Assert
var traces = testLoggerProvider.GetAllLogMessages();
var expectedTrace = traces.FirstOrDefault(val => val.EventId.Name.Equals("ScriptStartNotLoadingExtensionBundle"));
Assert.NotNull(expectedTrace);

AreExpectedMetricsGenerated(testMetricsLogger);
Assert.Single(types);
Assert.Equal(typeof(AzureStorageWebJobsStartup).FullName, types.Single().FullName);
}
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down