Skip to content

Commit 927ffda

Browse files
Adding check for dotnet-isolated app with extension bundle configured (#9466)
1 parent 7551395 commit 927ffda

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
103103
}
104104
}
105105

106+
bool isDotnetApp = isPrecompiledFunctionApp || IsDotnetIsolatedApp(workerConfigs);
107+
106108
if (SystemEnvironment.Instance.IsPlaceholderModeEnabled())
107109
{
108110
// Do not move this.
@@ -112,7 +114,7 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
112114

113115
string baseProbingPath = null;
114116

115-
if (bundleConfigured && (!isPrecompiledFunctionApp || isLegacyExtensionBundle))
117+
if (bundleConfigured && (!isDotnetApp || isLegacyExtensionBundle))
116118
{
117119
extensionsMetadataPath = await _extensionBundleManager.GetExtensionBundleBinPathAsync();
118120
if (string.IsNullOrEmpty(extensionsMetadataPath))
@@ -331,6 +333,16 @@ void CollectError(Type extensionType, Version minimumVersion, ExtensionStartupTy
331333
}
332334
}
333335

336+
private bool IsDotnetIsolatedApp(IList<RpcWorkerConfig> workerConfigs)
337+
{
338+
if (workerConfigs != null)
339+
{
340+
return workerConfigs.Where(config => config.Description is not null && config.Description.Language == RpcWorkerConstants.DotNetIsolatedLanguageWorkerName).Any();
341+
}
342+
343+
return false;
344+
}
345+
334346
private class TypeNameEqualityComparer : IEqualityComparer<Type>
335347
{
336348
public bool Equals(Type x, Type y)

test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,50 @@ public async Task GetExtensionsStartupTypes_LegacyBundles_UsesExtensionBundleBin
392392
}
393393
}
394394

395+
[Fact]
396+
public async Task GetExtensionsStartupTypes_DotnetIsolated_ExtensionBundleConfigured()
397+
{
398+
using (var directory = GetTempDirectory())
399+
{
400+
var binPath = Path.Combine(directory.Path, "bin");
401+
TestMetricsLogger testMetricsLogger = new TestMetricsLogger();
402+
TestLoggerProvider testLoggerProvider = new TestLoggerProvider();
403+
LoggerFactory factory = new LoggerFactory();
404+
factory.AddProvider(testLoggerProvider);
405+
var testLogger = factory.CreateLogger<ScriptStartupTypeLocator>();
406+
407+
var mockExtensionBundleManager = new Mock<IExtensionBundleManager>();
408+
mockExtensionBundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true);
409+
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).Returns(Task.FromResult(binPath));
410+
mockExtensionBundleManager.Setup(e => e.IsLegacyExtensionBundle()).Returns(false);
411+
mockExtensionBundleManager.Setup(e => e.GetExtensionBundleDetails()).Returns(Task.FromResult(GetV2BundleDetails()));
412+
413+
RpcWorkerConfig workerConfig = new RpcWorkerConfig() { Description = TestHelpers.GetTestWorkerDescription("dotnet-isolated", "none", true) };
414+
var tempOptions = new LanguageWorkerOptions();
415+
tempOptions.WorkerConfigs = new List<RpcWorkerConfig>();
416+
tempOptions.WorkerConfigs.Add(workerConfig);
417+
var optionsMonitor = new TestOptionsMonitor<LanguageWorkerOptions>(tempOptions);
418+
var mockFunctionMetadataManager = GetTestFunctionMetadataManager(optionsMonitor);
419+
420+
var languageWorkerOptions = new TestOptionsMonitor<LanguageWorkerOptions>(tempOptions);
421+
Environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "dotnet-isolated");
422+
423+
var discoverer = new ScriptStartupTypeLocator(directory.Path, testLogger, mockExtensionBundleManager.Object, mockFunctionMetadataManager, testMetricsLogger, languageWorkerOptions);
424+
425+
// Act
426+
var types = await discoverer.GetExtensionsStartupTypesAsync();
427+
428+
//Assert
429+
var traces = testLoggerProvider.GetAllLogMessages();
430+
var expectedTrace = traces.FirstOrDefault(val => val.EventId.Name.Equals("ScriptStartNotLoadingExtensionBundle"));
431+
Assert.NotNull(expectedTrace);
432+
433+
AreExpectedMetricsGenerated(testMetricsLogger);
434+
Assert.Single(types);
435+
Assert.Equal(typeof(AzureStorageWebJobsStartup).FullName, types.Single().FullName);
436+
}
437+
}
438+
395439
[Theory]
396440
[InlineData(false)]
397441
[InlineData(true)]

0 commit comments

Comments
 (0)