Skip to content

Commit 10e8492

Browse files
committed
Address PR feedback
1 parent 5b4d539 commit 10e8492

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

src/WebJobs.Script/Workers/Profiles/WorkerProfileManager.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,18 @@ namespace Microsoft.Azure.WebJobs.Script.Workers
1414
/// </summary>
1515
internal class WorkerProfileManager : IWorkerProfileManager
1616
{
17-
private const string LogCategory = "Host.WorkerProfiles";
18-
1917
private readonly ILogger _logger;
2018
private readonly IEnvironment _environment;
2119
private readonly IEnumerable<IWorkerProfileConditionProvider> _conditionProviders;
2220

2321
private string _activeProfile = string.Empty;
2422
private Dictionary<string, List<WorkerDescriptionProfile>> _profiles;
2523

26-
public WorkerProfileManager(ILoggerFactory loggerFactory, IEnvironment environment)
24+
public WorkerProfileManager(ILogger<WorkerProfileManager> logger, IEnvironment environment)
2725
{
28-
if (loggerFactory is null)
29-
{
30-
throw new ArgumentNullException(nameof(loggerFactory));
31-
}
32-
3326
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
27+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
3428

35-
_logger = loggerFactory.CreateLogger(LogCategory);
3629
_profiles = new Dictionary<string, List<WorkerDescriptionProfile>>();
3730
_conditionProviders = new List<IWorkerProfileConditionProvider>
3831
{

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Azure.WebJobs.Script.Workers.Profiles;
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.Logging;
13-
using Newtonsoft.Json;
1413
using Newtonsoft.Json.Linq;
1514

1615
namespace Microsoft.Azure.WebJobs.Script.Workers.Rpc
@@ -41,10 +40,8 @@ public RpcWorkerConfigFactory(IConfiguration config,
4140
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
4241
_metricsLogger = metricsLogger ?? throw new ArgumentNullException(nameof(metricsLogger));
4342
_profileManager = workerProfileManager ?? throw new ArgumentNullException(nameof(workerProfileManager));
44-
4543
_workerRuntime = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
4644

47-
string assemblyLocalPath = Path.GetDirectoryName(new Uri(typeof(RpcWorkerConfigFactory).Assembly.CodeBase).LocalPath);
4845
WorkersDirPath = GetDefaultWorkersDirectory(Directory.Exists);
4946
var workersDirectorySection = _config.GetSection($"{RpcWorkerConstants.LanguageWorkersSectionName}:{WorkerConstants.WorkersDirectorySectionName}");
5047

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using Microsoft.Extensions.Hosting;
2626
using Microsoft.Extensions.Options;
2727
using Moq;
28-
using Newtonsoft.Json.Linq;
2928

3029
namespace Microsoft.Azure.WebJobs.Script.Tests
3130
{

test/WebJobs.Script.Tests/Workers/Profiles/WorkerProfileManagerTests.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
using Microsoft.Azure.WebJobs.Script.Workers;
77
using Microsoft.Azure.WebJobs.Script.Workers.Profiles;
88
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
9-
using Microsoft.Extensions.Logging;
109
using Newtonsoft.Json.Linq;
1110
using Xunit;
1211

1312
namespace Microsoft.Azure.WebJobs.Script.Tests.Workers.Profiles
1413
{
1514
public class WorkerProfileManagerTests
1615
{
17-
private static LoggerFactory _testLoggerFactory = new LoggerFactory();
18-
private static TestEnvironment _testEnvironment = new TestEnvironment();
16+
private static TestLogger<WorkerProfileManager> _testLogger = new ();
17+
private static TestEnvironment _testEnvironment = new ();
1918

2019
[Fact]
2120
public void LoadWorkerDescriptionFromProfiles_ConditionsMet_ReturnsDescriptionWithChanges()
@@ -28,7 +27,7 @@ public void LoadWorkerDescriptionFromProfiles_ConditionsMet_ReturnsDescriptionWi
2827

2928
_testEnvironment.SetEnvironmentVariable("APPLICATIONINSIGHTS_ENABLE_AGENT", "true");
3029

31-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
30+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
3231
profileManager.SetWorkerDescriptionProfiles(profiles, "java");
3332
profileManager.LoadWorkerDescriptionFromProfiles(defaultDescription, out var evaluatedDescription);
3433

@@ -44,7 +43,7 @@ public void LoadWorkerDescriptionFromProfiles_NoConditionsMet_ReturnsDefaultDesc
4443
var profileDescription = RpcWorkerConfigTestUtilities.GetTestDefaultWorkerDescription("java", argumentListB);
4544
var profiles = WorkerDescriptionProfileData("java", profileDescription);
4645

47-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
46+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
4847
profileManager.SetWorkerDescriptionProfiles(profiles, "java");
4948
profileManager.LoadWorkerDescriptionFromProfiles(defaultDescription, out var evaluatedDescription);
5049

@@ -60,7 +59,7 @@ public void TryCreateWorkerProfileCondition_ValidCondition_ReturnsTrue()
6059
conditionJObject[WorkerConstants.WorkerDescriptionProfileConditionExpression] = "true";
6160
var conditionDescriptor = conditionJObject.ToObject<WorkerProfileConditionDescriptor>();
6261

63-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
62+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
6463
var result = profileManager.TryCreateWorkerProfileCondition(conditionDescriptor, out var condition);
6564

6665
Assert.True(result);
@@ -75,7 +74,7 @@ public void TryCreateWorkerProfileCondition_InvalidCondition_ReturnsFalse()
7574
conditionJObject[WorkerConstants.WorkerDescriptionProfileConditionExpression] = "true";
7675
var conditionDescriptor = conditionJObject.ToObject<WorkerProfileConditionDescriptor>();
7776

78-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
77+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
7978
var result = profileManager.TryCreateWorkerProfileCondition(conditionDescriptor, out var condition);
8079

8180
Assert.False(result);
@@ -90,7 +89,7 @@ public void IsCorrectProfileLoaded_NoChange_ReturnsTrue()
9089

9190
_testEnvironment.SetEnvironmentVariable("APPLICATIONINSIGHTS_ENABLE_AGENT", "true");
9291

93-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
92+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
9493
profileManager.SetWorkerDescriptionProfiles(profiles, "java");
9594
profileManager.LoadWorkerDescriptionFromProfiles(description, out var workerDescription);
9695

@@ -107,7 +106,7 @@ public void IsCorrectProfileLoaded_ConditionChange_ReturnsFalse()
107106

108107
_testEnvironment.SetEnvironmentVariable("APPLICATIONINSIGHTS_ENABLE_AGENT", "true");
109108

110-
WorkerProfileManager profileManager = new (_testLoggerFactory, _testEnvironment);
109+
WorkerProfileManager profileManager = new (_testLogger, _testEnvironment);
111110
profileManager.SetWorkerDescriptionProfiles(profiles, "java");
112111
profileManager.LoadWorkerDescriptionFromProfiles(description, out var workerDescription);
113112

@@ -119,15 +118,15 @@ public void IsCorrectProfileLoaded_ConditionChange_ReturnsFalse()
119118

120119
public static List<WorkerDescriptionProfile> WorkerDescriptionProfileData(string language, RpcWorkerDescription description)
121120
{
122-
var logger = _testLoggerFactory.CreateLogger("WorkerProfileManagerTests");
121+
var conditionLogger = new TestLogger("ConditionLogger");
123122
var profilesList = new List<WorkerDescriptionProfile>();
124123

125124
var conditionListA = new List<IWorkerProfileCondition>();
126-
conditionListA.Add(ProfilesTestUtilities.GetTestEnvironmentCondition(logger, _testEnvironment, "APPLICATIONINSIGHTS_ENABLE_AGENT", "true"));
125+
conditionListA.Add(ProfilesTestUtilities.GetTestEnvironmentCondition(conditionLogger, _testEnvironment, "APPLICATIONINSIGHTS_ENABLE_AGENT", "true"));
127126
var profileA = new WorkerDescriptionProfile("profileA", conditionListA, description);
128127

129128
var conditionListB = new List<IWorkerProfileCondition>();
130-
conditionListB.Add(ProfilesTestUtilities.GetTestEnvironmentCondition(logger, _testEnvironment, "APPLICATIONINSIGHTS_ENABLE_AGENT", "false"));
129+
conditionListB.Add(ProfilesTestUtilities.GetTestEnvironmentCondition(conditionLogger, _testEnvironment, "APPLICATIONINSIGHTS_ENABLE_AGENT", "false"));
131130
var profileB = new WorkerDescriptionProfile("profileB", conditionListB, description);
132131

133132
profilesList.Add(profileA);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Azure.WebJobs.Script.Workers.Profiles;
1111
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
1212
using Microsoft.Extensions.Configuration;
13-
using Microsoft.Extensions.Logging;
1413
using Newtonsoft.Json.Linq;
1514
using Xunit;
1615

@@ -25,8 +24,8 @@ public class RpcWorkerConfigFactoryTests : IDisposable
2524
public RpcWorkerConfigFactoryTests()
2625
{
2726
_testEnvironment = new TestEnvironment();
28-
var loggerFactory = new LoggerFactory();
29-
_testWorkerProfileManager = new WorkerProfileManager(loggerFactory, _testEnvironment);
27+
var workerProfileLogger = new TestLogger<WorkerProfileManager>();
28+
_testWorkerProfileManager = new WorkerProfileManager(workerProfileLogger, _testEnvironment);
3029
}
3130

3231
public void Dispose()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public WebHostRpcWorkerChannelManagerTests()
6060
WorkerConfigs = TestHelpers.GetTestWorkerConfigs()
6161
};
6262

63-
_workerProfileManager = new WorkerProfileManager(_loggerFactory, _testEnvironment);
63+
var workerProfileLogger = new TestLogger<WorkerProfileManager>();
64+
_workerProfileManager = new WorkerProfileManager(workerProfileLogger, _testEnvironment);
6465

6566
var applicationHostOptions = new ScriptApplicationHostOptions
6667
{

0 commit comments

Comments
 (0)