Skip to content

Commit f887dc8

Browse files
pragnagopafabiocav
authored andcommitted
Do not throw version error on runtime mismatch (#6171)
1 parent f314c0b commit f887dc8

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
@@ -189,10 +189,12 @@ internal void FormatWorkerPathIfNeeded(ISystemRuntimeInformation systemRuntimeIn
189189

190190
OSPlatform os = systemRuntimeInformation.GetOSPlatform();
191191
Architecture architecture = systemRuntimeInformation.GetOSArchitecture();
192+
string workerRuntime = environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
192193
string version = environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);
193194
logger.LogDebug($"EnvironmentVariable {RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName}: {version}");
194195

195-
if (!string.IsNullOrEmpty(version))
196+
// Only over-write DefaultRuntimeVersion if workerRuntime matches language for the worker config
197+
if (!string.IsNullOrEmpty(workerRuntime) && workerRuntime.Equals(Language, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(version))
196198
{
197199
DefaultRuntimeVersion = GetSanitizedRuntimeVersion(version);
198200
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ public void LanguageWorker_FormatWorkerPath_EnvironmentVersionSet(
368368
string sanitizeRuntimeVersionRegex,
369369
string expectedPath)
370370
{
371+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "python");
371372
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, environmentRuntimeVersion);
372-
373373
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
374374
{
375375
Arguments = new List<string>(),
@@ -571,6 +571,7 @@ public void LanguageWorker_FormatWorkerPath_UnsupportedEnvironmentRuntimeVersion
571571
string expectedExceptionMessage)
572572
{
573573
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "3.4");
574+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "python");
574575

575576
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
576577
{
@@ -597,6 +598,28 @@ public void LanguageWorker_FormatWorkerPath_UnsupportedEnvironmentRuntimeVersion
597598
Assert.Equal(ex.Message, expectedExceptionMessage);
598599
}
599600

601+
[Fact]
602+
public void LanguageWorker_FormatWorkerPath_DefualtRuntimeVersion_WorkerRuntimeMismatch()
603+
{
604+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, "13");
605+
_testEnvironment.SetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName, "node");
606+
607+
RpcWorkerDescription workerDescription = new RpcWorkerDescription()
608+
{
609+
Arguments = new List<string>(),
610+
DefaultExecutablePath = "python",
611+
SupportedRuntimeVersions = new List<string>() { "3.6", "3.7" },
612+
DefaultWorkerPath = $"{RpcWorkerConstants.RuntimeVersionPlaceholder}/worker.py",
613+
WorkerDirectory = string.Empty,
614+
Extensions = new List<string>() { ".py" },
615+
Language = "python",
616+
DefaultRuntimeVersion = "3.7" // Ignore this if environment is set
617+
};
618+
var testLogger = new TestLogger("test");
619+
workerDescription.FormatWorkerPathIfNeeded(_testSysRuntimeInfo, _testEnvironment, testLogger);
620+
Assert.Equal("3.7", workerDescription.DefaultRuntimeVersion);
621+
}
622+
600623
private IEnumerable<RpcWorkerConfig> TestReadWorkerProviderFromConfig(IEnumerable<TestRpcWorkerConfig> configs, ILogger testLogger, TestMetricsLogger testMetricsLogger, string language = null, Dictionary<string, string> keyValuePairs = null, bool appSvcEnv = false)
601624
{
602625
Mock<IEnvironment> mockEnvironment = new Mock<IEnvironment>();

0 commit comments

Comments
 (0)