Skip to content

Commit a53f92d

Browse files
committed
Refactor ScriptStartupTypeDiscovererTests for env isolation
1 parent ca6ce42 commit a53f92d

File tree

4 files changed

+480
-1033
lines changed

4 files changed

+480
-1033
lines changed

src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,37 @@ public sealed class ScriptStartupTypeLocator : IWebJobsStartupTypeLocator
3636
private readonly IExtensionBundleManager _extensionBundleManager;
3737
private readonly IFunctionMetadataManager _functionMetadataManager;
3838
private readonly IMetricsLogger _metricsLogger;
39-
private readonly Lazy<IEnumerable<Type>> _startupTypes;
39+
private readonly IEnvironment _environment;
4040
private readonly IOptions<ExtensionRequirementOptions> _extensionRequirementOptions;
41+
private readonly Lazy<IEnumerable<Type>> _startupTypes;
4142
private static string[] _builtinExtensionAssemblies = GetBuiltinExtensionAssemblies();
4243

43-
public ScriptStartupTypeLocator(string rootScriptPath, ILogger<ScriptStartupTypeLocator> logger, IExtensionBundleManager extensionBundleManager,
44-
IFunctionMetadataManager functionMetadataManager, IMetricsLogger metricsLogger, IOptions<ExtensionRequirementOptions> extensionRequirementOptions)
44+
public ScriptStartupTypeLocator(
45+
string rootScriptPath,
46+
ILogger<ScriptStartupTypeLocator> logger,
47+
IExtensionBundleManager extensionBundleManager,
48+
IFunctionMetadataManager functionMetadataManager,
49+
IMetricsLogger metricsLogger,
50+
IEnvironment environment,
51+
IOptions<ExtensionRequirementOptions> extensionRequirementOptions)
4552
{
4653
_rootScriptPath = rootScriptPath ?? throw new ArgumentNullException(nameof(rootScriptPath));
4754
_extensionBundleManager = extensionBundleManager ?? throw new ArgumentNullException(nameof(extensionBundleManager));
4855
_logger = logger;
4956
_functionMetadataManager = functionMetadataManager;
5057
_metricsLogger = metricsLogger;
51-
_startupTypes = new Lazy<IEnumerable<Type>>(() => GetExtensionsStartupTypesAsync().ConfigureAwait(false).GetAwaiter().GetResult());
58+
_environment = environment;
5259
_extensionRequirementOptions = extensionRequirementOptions;
60+
_startupTypes = new Lazy<IEnumerable<Type>>(() => GetExtensionsStartupTypesAsync().ConfigureAwait(false).GetAwaiter().GetResult());
5361
}
5462

5563
private static string[] GetBuiltinExtensionAssemblies()
5664
{
57-
return new[]
58-
{
65+
return
66+
[
5967
typeof(WebJobs.Extensions.Http.HttpWebJobsStartup).Assembly.GetName().Name,
6068
typeof(WebJobs.Extensions.ExtensionsWebJobsStartup).Assembly.GetName().Name
61-
};
69+
];
6270
}
6371

6472
public Type[] GetStartupTypes()
@@ -102,11 +110,11 @@ public async Task<IEnumerable<Type>> GetExtensionsStartupTypesAsync()
102110
}
103111
}
104112

105-
bool isDotnetIsolatedApp = Utility.IsDotnetIsolatedApp(SystemEnvironment.Instance, functionMetadataCollection);
113+
bool isDotnetIsolatedApp = Utility.IsDotnetIsolatedApp(_environment, functionMetadataCollection);
106114
bool isDotnetApp = isPrecompiledFunctionApp || isDotnetIsolatedApp;
107-
var isLogicApp = SystemEnvironment.Instance.IsLogicApp();
115+
var isLogicApp = _environment.IsLogicApp();
108116

109-
if (SystemEnvironment.Instance.IsPlaceholderModeEnabled())
117+
if (_environment.IsPlaceholderModeEnabled())
110118
{
111119
// Do not move this.
112120
// Calling this log statement in the placeholder mode to avoid jitting during specialization

src/WebJobs.Script/ScriptHostBuilderExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,13 @@ public static IHostBuilder AddScriptHost(this IHostBuilder builder,
142142
var bundleManager = new ExtensionBundleManager(extensionBundleOptions, SystemEnvironment.Instance, loggerFactory, configOption, httpClientFactory);
143143
var metadataServiceManager = applicationOptions.RootServiceProvider.GetService<IFunctionMetadataManager>();
144144

145-
ScriptStartupTypeLocator locator = new(
145+
var locator = new ScriptStartupTypeLocator(
146146
applicationOptions.ScriptPath,
147147
loggerFactory.CreateLogger<ScriptStartupTypeLocator>(),
148148
bundleManager,
149149
metadataServiceManager,
150150
metricsLogger,
151+
SystemEnvironment.Instance,
151152
extensionRequirementOptions);
152153

153154
// The locator (and thus the bundle manager) need to be created now in order to configure app configuration.

test/WebJobs.Script.Tests.Shared/TempDirectory.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,9 @@ public TempDirectory(string path)
1919
Directory.CreateDirectory(path);
2020
}
2121

22-
~TempDirectory()
23-
{
24-
Dispose(false);
25-
}
26-
2722
public string Path { get; }
2823

2924
public void Dispose()
30-
{
31-
GC.SuppressFinalize(this);
32-
Dispose(true);
33-
}
34-
35-
private void Dispose(bool disposing)
36-
{
37-
DeleteDirectory();
38-
}
39-
40-
private void DeleteDirectory()
4125
{
4226
try
4327
{

0 commit comments

Comments
 (0)