Skip to content

Test warning log for DF external SDK #912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DurableWorker/DurableController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class DurableController
private readonly ILogger _logger;

private bool isExternalDFSdkEnabled { get; } =
PowerShellWorkerConfiguration.GetBoolean("ExternalDurablePowerShellSDK") ?? false;
PowerShellWorkerConfiguration.GetBoolean(Utils.ExternalDurableSdkEnvVariable) ?? false;

public DurableController(
DurableFunctionInfo durableDurableFunctionInfo,
Expand Down Expand Up @@ -81,7 +81,7 @@ private void tryEnablingExternalSDK()
else if (isExternalSdkLoaded)
{
// External SDK is in the session, but customer did not explicitly enable it. Report the potential of runtime errors.
_logger.Log(isUserOnlyLog: false, LogLevel.Error, String.Format(PowerShellWorkerStrings.PotentialDurableSDKClash, Utils.ExternalDurableSdkName));
_logger.Log(isUserOnlyLog: false, LogLevel.Error, String.Format(PowerShellWorkerStrings.PotentialDurableSDKClash, Utils.ExternalDurableSdkName, Utils.ExternalDurableSdkEnvVariable));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Utility/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class Utils
internal const string ExternalDurableSdkName = "AzureFunctions.PowerShell.Durable.SDK";
internal const string IsOrchestrationFailureKey = "IsOrchestrationFailure";
internal const string TracePipelineObjectCmdlet = "Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject";
internal const string ExternalDurableSdkEnvVariable = "ExternalDurablePowerShellSDK";

internal readonly static object BoxedTrue = (object)true;
internal readonly static object BoxedFalse = (object)false;
Expand Down
41 changes: 39 additions & 2 deletions test/Unit/Durable/DurableControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,37 @@ internal void ExternalDurableSdkIsNotConfiguredByDefault(DurableFunctionType dur
_mockPowerShellServices.Verify(_ => _.EnableExternalDurableSDK(), Times.Never);
}

[Fact]
internal void WarnsUserToSetExternalSdkEnvVariable()
{
// "forget" to enable DF external SDK through enviroment variable
Environment.SetEnvironmentVariable("ExternalDurablePowerShellSDK", "false");

var mockLogger = new Mock<ILogger>();
var durableFunctionType = DurableFunctionType.OrchestrationFunction;
var durableController = CreateDurableController(durableFunctionType, logger: mockLogger.Object);
var inputData = GetDurableBindings(durableFunctionType);

_mockPowerShellServices.Setup(_ => _.SetOrchestrationContext(
It.IsAny<ParameterBinding>(),
out It.Ref<IExternalOrchestrationInvoker>.IsAny)).Returns(_orchestrationBindingInfo);
_mockOrchestrationInvoker.Setup(_ => _.SetExternalInvoker(It.IsAny<IExternalOrchestrationInvoker>()));

_mockPowerShellServices.Setup(_ => _.HasExternalDurableSDK()).Returns(false);
_mockPowerShellServices.Setup(_ => _.EnableExternalDurableSDK()).Throws(new Exception("should not be called"));

// detect SDK is loaded
_mockPowerShellServices.Setup(_ => _.isExternalDurableSdkLoaded()).Returns(true);
durableController.InitializeBindings(inputData, out var hasExternalSDK);

Assert.False(hasExternalSDK);
_mockPowerShellServices.Verify(_ => _.EnableExternalDurableSDK(), Times.Never);

// validate that warning is communicated through the logger
var expectedMessage = string.Format(PowerShellWorkerStrings.PotentialDurableSDKClash, Utils.ExternalDurableSdkName, Utils.ExternalDurableSdkEnvVariable);
mockLogger.Verify(_ => _.Log(false, RpcLog.Types.Level.Error, It.Is<string>(s => s.Equals(expectedMessage)), null), Times.Once);
}

[Theory]
[InlineData(DurableFunctionType.None)]
[InlineData(DurableFunctionType.OrchestrationFunction)]
Expand Down Expand Up @@ -328,15 +359,21 @@ internal void ExternalDurableSdkCanBeEnabled(DurableFunctionType durableFunction

private DurableController CreateDurableController(
DurableFunctionType durableFunctionType,
string durableClientBindingName = null)
string durableClientBindingName = null,
ILogger logger = null)
{
var durableFunctionInfo = new DurableFunctionInfo(durableFunctionType, durableClientBindingName);

if (logger == null)
{
logger = _testLogger;
}

return new DurableController(
durableFunctionInfo,
_mockPowerShellServices.Object,
_mockOrchestrationInvoker.Object,
_testLogger);
logger);
}

private static ParameterBinding CreateParameterBinding(string parameterName, object value)
Expand Down