Skip to content

Commit 62408d9

Browse files
authored
[Rpc]Port fix(#6352) (#6357)
1 parent 75d1e6e commit 62408d9

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/WebJobs.Script/Workers/Rpc/Configuration/RpcWorkerConfigFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ internal void AddProvider(string workerDir)
152152
workerDescription.FormatWorkerPathIfNeeded(_systemRuntimeInformation, _environment, _logger);
153153
workerDescription.ThrowIfFileNotExists(workerDescription.DefaultWorkerPath, nameof(workerDescription.DefaultWorkerPath));
154154
_workerDescripionDictionary[workerDescription.Language] = workerDescription;
155+
workerDescription.ExpandEnvironmentVariables();
155156
_logger.LogDebug($"Added WorkerConfig for language: {workerDescription.Language}");
156157
}
157158
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public override void ApplyDefaultsAndValidate(string workerDirectory, ILogger lo
8080
{
8181
DefaultWorkerPath = Path.Combine(WorkerDirectory, DefaultWorkerPath);
8282
}
83-
ExpandEnvironmentVariables();
8483
if (string.IsNullOrEmpty(Language))
8584
{
8685
throw new ValidationException($"WorkerDescription {nameof(Language)} cannot be empty");

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Runtime.InteropServices;
98
using Microsoft.Azure.WebJobs.Script.Config;
109
using Microsoft.Azure.WebJobs.Script.Workers;
1110
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
1211
using Microsoft.Extensions.Configuration;
13-
using Moq;
1412
using Xunit;
1513

1614
namespace Microsoft.Azure.WebJobs.Script.Tests.Workers.Rpc
@@ -106,29 +104,47 @@ public void JavaPath_FromEnvVars()
106104
[Fact]
107105
public void DefaultWorkerConfigs_Overrides_DefaultWorkerRuntimeVersion_AppSetting()
108106
{
107+
var testEnvVariables = new Dictionary<string, string>
108+
{
109+
{ "languageWorkers:python:defaultRuntimeVersion", "3.7" }
110+
};
109111
var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
110-
.AddInMemoryCollection(new Dictionary<string, string>
111-
{
112-
["languageWorkers:python:defaultRuntimeVersion"] = "3.6"
113-
});
112+
.AddInMemoryCollection(testEnvVariables);
114113
var config = configBuilder.Build();
115114
var scriptSettingsManager = new ScriptSettingsManager(config);
116115
var testLogger = new TestLogger("test");
117-
var testEnvVariables = new Dictionary<string, string>
118-
{
119-
{ "languageWorkers:python:defaultRuntimeVersion", "3.6" }
120-
};
121116
using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
122117
{
123118
var configFactory = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment, new TestMetricsLogger());
124119
var workerConfigs = configFactory.GetConfigs();
125120
var pythonWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("python", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
121+
var powershellWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("powershell", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
126122
Assert.Equal(4, workerConfigs.Count);
127123
Assert.NotNull(pythonWorkerConfig);
128-
Assert.Equal("3.6", pythonWorkerConfig.Description.DefaultRuntimeVersion);
124+
Assert.NotNull(powershellWorkerConfig);
125+
Assert.Equal("3.7", pythonWorkerConfig.Description.DefaultRuntimeVersion);
126+
Assert.Null(powershellWorkerConfig.Description.DefaultRuntimeVersion);
129127
}
130128
}
131129

130+
[Fact]
131+
public void DefaultWorkerConfigs_Overrides_VersionAppSetting()
132+
{
133+
var testEnvironment = new TestEnvironment();
134+
testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME_VERSION", "3.7");
135+
testEnvironment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "python");
136+
var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder();
137+
var config = configBuilder.Build();
138+
var scriptSettingsManager = new ScriptSettingsManager(config);
139+
var testLogger = new TestLogger("test");
140+
var configFactory = new RpcWorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, testEnvironment, new TestMetricsLogger());
141+
var workerConfigs = configFactory.GetConfigs();
142+
var pythonWorkerConfig = workerConfigs.Where(w => w.Description.Language.Equals("python", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
143+
Assert.Equal(1, workerConfigs.Count);
144+
Assert.NotNull(pythonWorkerConfig);
145+
Assert.Equal("3.7", pythonWorkerConfig.Description.DefaultRuntimeVersion);
146+
}
147+
132148
[Theory]
133149
[InlineData("python", "Python", false, true)]
134150
[InlineData("python", "NOde", false, false)]

0 commit comments

Comments
 (0)