public void InvokeBasicFunctionWithRequiresWorks() { string path = Path.Join(s_funcDirectory, "testBasicFunctionWithRequires.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); Hashtable result = InvokeFunction(testManager, functionInfo); // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction' Hashtable outputBindings = FunctionMetadata.GetOutputBindingHashtable(testManager.InstanceId); Assert.Empty(outputBindings); // When function script has #requires, not PowerShell function will be created for the Az function, // and the invocation uses the file path directly. string expectedResult = $"{TestStringData},ThreadJob,testBasicFunctionWithRequires.ps1"; Assert.Equal(expectedResult, result[TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
public void InvokeBasicFunctionWithTriggerMetadataAndTraceContextWorks() { string path = Path.Join(s_funcDirectory, "testBasicFunctionWithTriggerMetadata.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); Hashtable triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase) { { TestInputBindingName, TestStringData } }; try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); Hashtable result = InvokeFunction(testManager, functionInfo, triggerMetadata); // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction' Hashtable outputBindings = FunctionMetadata.GetOutputBindingHashtable(testManager.InstanceId); Assert.Empty(outputBindings); // A PowerShell function should be created fro the Az function. string expectedResult = $"{TestStringData},{functionInfo.DeployedPSFuncName}"; Assert.Equal(expectedResult, result[TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
/// <summary> /// Return a used PowerShellManager instance to the pool. /// </summary> internal void ReclaimUsedWorker(PowerShellManager psManager) { if (psManager != null) { // Unregister the Runspace before reclaiming the used PowerShellManager. FunctionMetadata.UnregisterFunctionMetadata(psManager.InstanceId); psManager.Logger.ResetContext(); _pool.Add(psManager); } }
public void RegisterAndUnregisterFunctionMetadataShouldWork() { string path = Path.Join(TestUtils.FunctionDirectory, "testBasicFunction.ps1"); var functionInfo = TestUtils.NewAzFunctionInfo(path, string.Empty); Assert.Empty(FunctionMetadata.OutputBindingCache); FunctionMetadata.RegisterFunctionMetadata(_testManager.InstanceId, functionInfo); Assert.Single(FunctionMetadata.OutputBindingCache); FunctionMetadata.UnregisterFunctionMetadata(_testManager.InstanceId); Assert.Empty(FunctionMetadata.OutputBindingCache); }
public void RegisterAndUnregisterFunctionMetadataShouldWork() { string path = Path.Join(s_funcDirectory, "testBasicFunction.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); var outBindingMap = FunctionMetadata.GetOutputBindingInfo(testManager.InstanceId); Assert.Single(outBindingMap); Assert.Equal(TestOutputBindingName, outBindingMap.First().Key); FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); outBindingMap = FunctionMetadata.GetOutputBindingInfo(testManager.InstanceId); Assert.Null(outBindingMap); }
public void InvokeFunctionWithEntryPointWorks() { string path = Path.Join(TestUtils.FunctionDirectory, "testFunctionWithEntryPoint.psm1"); var functionInfo = TestUtils.NewAzFunctionInfo(path, "Run"); try { FunctionMetadata.RegisterFunctionMetadata(_testManager.InstanceId, functionInfo); Hashtable result = _testManager.InvokeFunction(functionInfo, null, _testInputData); Assert.Equal(TestStringData, result[TestUtils.TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(_testManager.InstanceId); } }
public void FunctionShouldCleanupVariableTable() { string path = Path.Join(TestUtils.FunctionDirectory, "testFunctionCleanup.ps1"); var functionInfo = TestUtils.NewAzFunctionInfo(path, string.Empty); try { FunctionMetadata.RegisterFunctionMetadata(_testManager.InstanceId, functionInfo); Hashtable result1 = _testManager.InvokeFunction(functionInfo, null, _testInputData); Assert.Equal("is not set", result1[TestUtils.TestOutputBindingName]); // the value should not change if the variable table is properly cleaned up. Hashtable result2 = _testManager.InvokeFunction(functionInfo, null, _testInputData); Assert.Equal("is not set", result2[TestUtils.TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(_testManager.InstanceId); } }
public void InvokeBasicFunctionWithTriggerMetadataWorks() { string path = Path.Join(TestUtils.FunctionDirectory, "testBasicFunctionWithTriggerMetadata.ps1"); var functionInfo = TestUtils.NewAzFunctionInfo(path, string.Empty); Hashtable triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase) { { TestUtils.TestInputBindingName, TestStringData } }; try { FunctionMetadata.RegisterFunctionMetadata(_testManager.InstanceId, functionInfo); Hashtable result = _testManager.InvokeFunction(functionInfo, triggerMetadata, _testInputData); Assert.Equal(TestStringData, result[TestUtils.TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(_testManager.InstanceId); } }
public void FunctionShouldCleanupVariableTable() { string path = Path.Join(s_funcDirectory, "testFunctionCleanup.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); Hashtable result1 = InvokeFunction(testManager, functionInfo); Assert.Equal("is not set", result1[TestOutputBindingName]); // the value should not change if the variable table is properly cleaned up. Hashtable result2 = InvokeFunction(testManager, functionInfo); Assert.Equal("is not set", result2[TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
public void InvokeFunctionWithEntryPointWorks() { string path = Path.Join(s_funcDirectory, "testFunctionWithEntryPoint.psm1"); var(functionInfo, testManager) = PrepareFunction(path, "Run"); try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); Hashtable result = InvokeFunction(testManager, functionInfo); // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction' Hashtable outputBindings = FunctionMetadata.GetOutputBindingHashtable(testManager.InstanceId); Assert.Empty(outputBindings); string expectedResult = $"{TestStringData},Run"; Assert.Equal(expectedResult, result[TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
public void InvokeFunctionWithSpecialVariableWorks() { string path = Path.Join(s_funcDirectory, "testBasicFunctionSpecialVariables.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo); Hashtable result = InvokeFunction(testManager, functionInfo); // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction' Hashtable outputBindings = FunctionMetadata.GetOutputBindingHashtable(testManager.InstanceId); Assert.Empty(outputBindings); // A PowerShell function should be created fro the Az function. string expectedResult = $"{s_funcDirectory},{path},{functionInfo.DeployedPSFuncName}"; Assert.Equal(expectedResult, result[TestOutputBindingName]); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces) { s_testLogger.FullLog.Clear(); var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1"); var(functionInfo, testManager) = PrepareFunction(path, string.Empty); functionInfo.DurableFunctionInfo.Type = durableFunctionType; try { FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings); var result = testManager.InvokeFunction(functionInfo, null, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch()); var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList(); var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" }; Assert.Equal(expected, relevantLogs); } finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); } }
public void Dispose() { FunctionMetadata.UnregisterFunctionMetadata(s_pwsh.Runspace.InstanceId); s_pwsh.AddScript("Get-OutputBinding -Purge").InvokeAndClearCommands(); }