Skip to content

Commit bbb3d25

Browse files
authored
allowing workers to handle .dll file extensions (#6378)
1 parent 511e932 commit bbb3d25

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/WebJobs.Script/Host/FunctionMetadataProvider.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ internal static string ParseLanguage(string scriptFilePath, IEnumerable<RpcWorke
170170

171171
// determine the script type based on the primary script file extension
172172
string extension = Path.GetExtension(scriptFilePath).ToLowerInvariant().TrimStart('.');
173+
var workerConfig = workerConfigs.FirstOrDefault(config => config.Description.Extensions.Contains("." + extension));
174+
if (workerConfig != null)
175+
{
176+
return workerConfig.Description.Language;
177+
}
178+
179+
// If no worker claimed these extensions, use in-proc.
173180
switch (extension)
174181
{
175182
case "csx":
@@ -178,11 +185,7 @@ internal static string ParseLanguage(string scriptFilePath, IEnumerable<RpcWorke
178185
case "dll":
179186
return DotNetScriptTypes.DotNetAssembly;
180187
}
181-
var workerConfig = workerConfigs.FirstOrDefault(config => config.Description.Extensions.Contains("." + extension));
182-
if (workerConfig != null)
183-
{
184-
return workerConfig.Description.Language;
185-
}
188+
186189
return null;
187190
}
188191

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,21 @@ public static async Task<string> ReadStreamToEnd(Stream stream)
256256
}
257257
}
258258

259-
public static IList<RpcWorkerConfig> GetTestWorkerConfigs()
259+
public static IList<RpcWorkerConfig> GetTestWorkerConfigs(bool includeDllWorker = false)
260260
{
261-
var nodeWorkerDesc = GetTestWorkerDescription("node", ".js");
262-
var javaWorkerDesc = GetTestWorkerDescription("java", ".jar");
263-
264-
return new List<RpcWorkerConfig>()
261+
var workerConfigs = new List<RpcWorkerConfig>
265262
{
266-
new RpcWorkerConfig() { Description = nodeWorkerDesc },
267-
new RpcWorkerConfig() { Description = javaWorkerDesc },
263+
new RpcWorkerConfig() { Description = GetTestWorkerDescription("node", ".js") },
264+
new RpcWorkerConfig() { Description = GetTestWorkerDescription("java", ".jar") }
268265
};
266+
267+
// Allow tests to have a worker that claims the .dll extension.
268+
if (includeDllWorker)
269+
{
270+
workerConfigs.Add(new RpcWorkerConfig() { Description = GetTestWorkerDescription("dllWorker", ".dll") });
271+
}
272+
273+
return workerConfigs;
269274
}
270275

271276
public static LanguageWorkerOptions GetTestLanguageWorkerOptions()

test/WebJobs.Script.Tests/FunctionMetadataProviderTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1010
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
1111
using Microsoft.Extensions.Logging.Abstractions;
12-
using Microsoft.Extensions.Options;
1312
using Newtonsoft.Json.Linq;
1413
using Xunit;
1514

@@ -116,15 +115,16 @@ public void ValidateFunctionName_DoesNotThrowOnValidName(string functionName)
116115
}
117116

118117
[Theory]
119-
[InlineData("node", "test.js")]
120-
[InlineData("java", "test.jar")]
121-
[InlineData("CSharp", "test.cs")]
122-
[InlineData("CSharp", "test.csx")]
123-
[InlineData("DotNetAssembly", "test.dll")]
124-
[InlineData(null, "test.x")]
125-
public void ParseLanguage_Returns_ExpectedLanguage(string language, string scriptFile)
118+
[InlineData("node", "test.js", false)]
119+
[InlineData("java", "test.jar", false)]
120+
[InlineData("CSharp", "test.cs", false)]
121+
[InlineData("CSharp", "test.csx", false)]
122+
[InlineData("dllWorker", "test.dll", true)] // The test "dllWorker" will claim ".dll" extensions before falling back to DotNetAssembly
123+
[InlineData("DotNetAssembly", "test.dll", false)]
124+
[InlineData(null, "test.x", false)]
125+
public void ParseLanguage_Returns_ExpectedLanguage(string language, string scriptFile, bool includeDllWorker)
126126
{
127-
Assert.Equal(language, FunctionMetadataProvider.ParseLanguage(scriptFile, TestHelpers.GetTestWorkerConfigs()));
127+
Assert.Equal(language, FunctionMetadataProvider.ParseLanguage(scriptFile, TestHelpers.GetTestWorkerConfigs(includeDllWorker: includeDllWorker)));
128128
}
129129

130130
[Theory]

0 commit comments

Comments
 (0)