Skip to content

Commit 739f1aa

Browse files
pragnagopafabiocav
authored andcommitted
[Port]Do not throw version error on runtime mismatch (#6140)
1 parent 49a47a2 commit 739f1aa

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/WebJobs.Script/Workers/Rpc/RpcWorkerDescription.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ internal void FormatWorkerPathIfNeeded(ISystemRuntimeInformation systemRuntimeIn
182182

183183
OSPlatform os = systemRuntimeInformation.GetOSPlatform();
184184
Architecture architecture = systemRuntimeInformation.GetOSArchitecture();
185+
string workerRuntime = environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
185186
string version = environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);
186187
logger.LogDebug($"EnvironmentVariable {RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName}: {version}");
187188

188-
if (!string.IsNullOrEmpty(version))
189+
// Only over-write DefaultRuntimeVersion if workerRuntime matches language for the worker config
190+
if (!string.IsNullOrEmpty(workerRuntime) && workerRuntime.Equals(Language, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(version))
189191
{
190192
DefaultRuntimeVersion = version;
191193
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_W
362362
[InlineData("%FUNCTIONS_WORKER_RUNTIME_VERSION%/{os}", "3.7/LINUX")]
363363
public void LanguageWorker_FormatWorkerPath_EnvironmentVersionSet(string defaultWorkerPath, string expectedPath)
364364
{
365+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "python");
365366
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.7");
366-
367367
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
368368
{
369369
Arguments = new List<string>(),
@@ -551,6 +551,7 @@ public void LanguageWorker_FormatWorkerPath_UnsupportedDefaultRuntimeVersion()
551551
public void LanguageWorker_FormatWorkerPath_UnsupportedEnvironmentRuntimeVersion()
552552
{
553553
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.4");
554+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "python");
554555

555556
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
556557
{
@@ -576,6 +577,28 @@ public void LanguageWorker_FormatWorkerPath_UnsupportedEnvironmentRuntimeVersion
576577
Assert.Equal(ex.Message, $"Version 3.4 is not supported for language {workerDescription.Language}");
577578
}
578579

580+
[Fact]
581+
public void LanguageWorker_FormatWorkerPath_DefualtRuntimeVersion_WorkerRuntimeMismatch()
582+
{
583+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "13");
584+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "node");
585+
586+
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
587+
{
588+
Arguments = new List<string>(),
589+
DefaultExecutablePath = "python",
590+
SupportedRuntimeVersions = new List<string>() { "3.6", "3.7" },
591+
DefaultWorkerPath = $"{RpcWorkerConstants.RuntimeVersionPlaceholder}/worker.py",
592+
WorkerDirectory = string.Empty,
593+
Extensions = new List<string>() { ".py" },
594+
Language = "python",
595+
DefaultRuntimeVersion = "3.7" // Ignore this if environment is set
596+
};
597+
var testLogger = new TestLogger("test");
598+
workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger);
599+
Assert.Equal("3.7", workerDescription.DefaultRuntimeVersion);
600+
}
601+
579602
private IEnumerable<RpcWorkerConfig> TestReadWorkerProviderFromConfig(IEnumerable<TestRpcWorkerConfig> configs, ILogger testLogger, TestMetricsLogger testMetricsLogger, string language = null, Dictionary<string, string> keyValuePairs = null, bool appSvcEnv = false)
580603
{
581604
Mock<IEnvironment> mockEnvironment = new Mock<IEnvironment>();

0 commit comments

Comments
 (0)