Skip to content

Commit a17f811

Browse files
4.1.2 Hotfix (#8042)
* Figure out FUNCTIONS_WORKER_RUNTIME from function app content if Environment variable FUNCTIONS_WORKER_RUNTIME is not set (#8033) * Taking worker runtime from files if not in Env setting * Added tests * Code cleanup * Added tests in Utility * minor restructuring in utility * Update common.props Co-authored-by: Surgupta <[email protected]>
1 parent f23a5d2 commit a17f811

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

build/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<MajorVersion>4</MajorVersion>
77
<MinorVersion>1</MinorVersion>
8-
<PatchVersion>1</PatchVersion>
8+
<PatchVersion>2</PatchVersion>
99
<BuildNumber Condition="'$(BuildNumber)' == '' ">0</BuildNumber>
1010
<PreviewVersion></PreviewVersion>
1111

src/WebJobs.Script/Utility.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,21 @@ internal static bool IsSingleLanguage(IEnumerable<FunctionMetadata> functions, s
631631
return ContainsFunctionWithWorkerRuntime(filteredFunctions, workerRuntime);
632632
}
633633

634-
internal static string GetWorkerRuntime(IEnumerable<FunctionMetadata> functions)
634+
internal static string GetWorkerRuntime(IEnumerable<FunctionMetadata> functions, IEnvironment environment = null)
635635
{
636-
if (IsSingleLanguage(functions, null))
636+
string workerRuntime = null;
637+
638+
if (environment != null)
639+
{
640+
workerRuntime = environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
641+
642+
if (!string.IsNullOrEmpty(workerRuntime))
643+
{
644+
return workerRuntime;
645+
}
646+
}
647+
648+
if (functions != null && IsSingleLanguage(functions, null))
637649
{
638650
var filteredFunctions = functions?.Where(f => !f.IsCodeless());
639651
string functionLanguage = filteredFunctions.FirstOrDefault()?.Language;

src/WebJobs.Script/Workers/Rpc/FunctionRegistration/RpcFunctionInvocationDispatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
217217
return;
218218
}
219219

220-
_workerRuntime = _workerRuntime ?? _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
220+
_workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions, _environment);
221+
221222
if (string.IsNullOrEmpty(_workerRuntime) || _workerRuntime.Equals(RpcWorkerConstants.DotNetLanguageWorkerName, StringComparison.InvariantCultureIgnoreCase))
222223
{
223224
// Shutdown any placeholder channels for empty function apps or dotnet function apps.

test/WebJobs.Script.Tests/UtilityTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,27 @@ public void IsSupported_Returns_True(string language, string funcMetadataLanguag
595595
Assert.True(Utility.IsFunctionMetadataLanguageSupportedByWorkerRuntime(func1, language));
596596
}
597597

598+
[Theory]
599+
[InlineData(null)]
600+
[InlineData("java")]
601+
public void GetWorkerRuntimeTests(string workerRuntime)
602+
{
603+
FunctionMetadata func1 = new FunctionMetadata()
604+
{
605+
Name = "func1",
606+
Language = workerRuntime
607+
};
608+
609+
IEnumerable<FunctionMetadata> functionMetadatas = new List<FunctionMetadata>
610+
{
611+
func1
612+
};
613+
614+
var testEnv = new TestEnvironment();
615+
testEnv.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, workerRuntime);
616+
Assert.True(Utility.GetWorkerRuntime(functionMetadatas, testEnv) == workerRuntime);
617+
}
618+
598619
[Theory]
599620
[InlineData("node", "java")]
600621
[InlineData("java", "node")]

test/WebJobs.Script.Tests/Workers/Rpc/RpcFunctionInvocationDispatcherTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,41 @@ public async Task WorkerIndexing_Setting_ChannelInitializationState_Succeeds()
126126
Assert.Equal(expectedProcessCount, initializedChannelsCount);
127127
}
128128

129+
[Theory]
130+
[InlineData(null)]
131+
[InlineData(RpcWorkerConstants.JavaLanguageWorkerName)]
132+
public async Task WorkerRuntime_Setting_ChannelInitializationState_Succeeds(string workerRuntime)
133+
{
134+
_testLoggerProvider.ClearAllLogMessages();
135+
int expectedProcessCount = 1;
136+
RpcFunctionInvocationDispatcher functionDispatcher = GetTestFunctionDispatcher(expectedProcessCount, false, runtime: workerRuntime, workerIndexing: true);
137+
138+
// create channels and ensure that they aren't ready for invocation requests yet
139+
await functionDispatcher.InitializeAsync(new List<FunctionMetadata>());
140+
141+
if (!string.IsNullOrEmpty(workerRuntime))
142+
{
143+
int createdChannelsCount = await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount, false);
144+
Assert.Equal(expectedProcessCount, createdChannelsCount);
145+
146+
IEnumerable<IRpcWorkerChannel> channels = await functionDispatcher.GetInitializedWorkerChannelsAsync();
147+
Assert.Equal(0, channels.Count());
148+
149+
// set up invocation buffers, send load requests, and ensure that the channels are now set up for invocation requests
150+
var functions = GetTestFunctionsList(RpcWorkerConstants.JavaLanguageWorkerName);
151+
await functionDispatcher.FinishInitialization(functions);
152+
int initializedChannelsCount = await WaitForJobhostWorkerChannelsToStartup(functionDispatcher, expectedProcessCount, true);
153+
Assert.Equal(expectedProcessCount, initializedChannelsCount);
154+
}
155+
else
156+
{
157+
foreach (var currChannel in functionDispatcher.JobHostLanguageWorkerChannelManager.GetChannels())
158+
{
159+
Assert.True(((TestRpcWorkerChannel)currChannel).ExecutionContexts.Count == 0);
160+
}
161+
}
162+
}
163+
129164
[Fact]
130165
public async Task Starting_MultipleJobhostChannels_Failed()
131166
{

0 commit comments

Comments
 (0)