Skip to content

Commit

Permalink
Adding check for dotnet-isolated app with extension bundle configured (
Browse files Browse the repository at this point in the history
  • Loading branch information
surgupta-msft authored Aug 16, 2023
1 parent 7551395 commit 927ffda
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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);

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

0 comments on commit 927ffda

Please sign in to comment.