@@ -105,7 +105,7 @@ public void InvokeBasicFunctionWorks()
105105
106106 try
107107 {
108- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
108+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
109109 Hashtable result = InvokeFunction ( testManager , functionInfo ) ;
110110
111111 // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction'
@@ -130,7 +130,7 @@ public void InvokeFunctionWithSpecialVariableWorks()
130130
131131 try
132132 {
133- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
133+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
134134 Hashtable result = InvokeFunction ( testManager , functionInfo ) ;
135135
136136 // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction'
@@ -155,7 +155,7 @@ public void InvokeBasicFunctionWithRequiresWorks()
155155
156156 try
157157 {
158- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
158+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
159159 Hashtable result = InvokeFunction ( testManager , functionInfo ) ;
160160
161161 // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction'
@@ -186,7 +186,7 @@ public void InvokeBasicFunctionWithTriggerMetadataAndTraceContextWorks()
186186
187187 try
188188 {
189- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
189+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
190190
191191 Hashtable result = InvokeFunction ( testManager , functionInfo , triggerMetadata ) ;
192192
@@ -212,7 +212,7 @@ public void InvokeFunctionWithEntryPointWorks()
212212
213213 try
214214 {
215- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
215+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
216216 Hashtable result = InvokeFunction ( testManager , functionInfo ) ;
217217
218218 // The outputBinding hashtable for the runspace should be cleared after 'InvokeFunction'
@@ -236,7 +236,7 @@ public void FunctionShouldCleanupVariableTable()
236236
237237 try
238238 {
239- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
239+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
240240
241241 Hashtable result1 = InvokeFunction ( testManager , functionInfo ) ;
242242 Assert . Equal ( "is not set" , result1 [ TestOutputBindingName ] ) ;
@@ -266,7 +266,7 @@ public void RegisterAndUnregisterFunctionMetadataShouldWork()
266266 string path = Path . Join ( s_funcDirectory , "testBasicFunction.ps1" ) ;
267267 var ( functionInfo , testManager ) = PrepareFunction ( path , string . Empty ) ;
268268
269- FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo ) ;
269+ FunctionMetadata . RegisterFunctionMetadata ( testManager . InstanceId , functionInfo . OutputBindings ) ;
270270 var outBindingMap = FunctionMetadata . GetOutputBindingInfo ( testManager . InstanceId ) ;
271271 Assert . Single ( outBindingMap ) ;
272272 Assert . Equal ( TestOutputBindingName , outBindingMap . First ( ) . Key ) ;
@@ -317,7 +317,7 @@ public void ProfileWithTerminatingError()
317317 Assert . Throws < CmdletInvocationException > ( ( ) => testManager . InvokeProfile ( profilePath ) ) ;
318318 var relevantLogs = s_testLogger . FullLog . Where ( message => ! message . StartsWith ( "Trace:" ) ) . ToList ( ) ;
319319 Assert . Single ( relevantLogs ) ;
320- Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 0 ] ) ;
320+ Assert . Matches ( "Error: Errors reported while executing profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 0 ] ) ;
321321 }
322322
323323 [ Fact ]
@@ -334,7 +334,7 @@ public void ProfileWithNonTerminatingError()
334334 Assert . Equal ( 2 , relevantLogs . Count ) ;
335335 Assert . StartsWith ( "Error: ERROR: " , relevantLogs [ 0 ] ) ;
336336 Assert . Contains ( "help me!" , relevantLogs [ 0 ] ) ;
337- Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 1 ] ) ;
337+ Assert . Matches ( "Error: Errors reported while executing profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 1 ] ) ;
338338 }
339339
340340 [ Fact ]
@@ -358,9 +358,44 @@ public void PSManagerCtorDoesNotRunProfileIfDelayInit()
358358 Assert . Empty ( s_testLogger . FullLog ) ;
359359 }
360360
361+ [ Fact ]
362+ public void LoggerContextIsSet ( )
363+ {
364+ var dummyBindingInfo = new Dictionary < string , ReadOnlyBindingInfo > ( ) ;
365+ var outputBindings = new ReadOnlyDictionary < string , ReadOnlyBindingInfo > ( dummyBindingInfo ) ;
366+
367+ var powerShellManagerPool = new PowerShellManagerPool ( ( ) => new ContextValidatingLogger ( ) ) ;
368+ var pwsh = Utils . NewPwshInstance ( ) ;
369+ powerShellManagerPool . Initialize ( pwsh ) ;
370+
371+ var worker = powerShellManagerPool . CheckoutIdleWorker ( "requestId" , "invocationId" , "FuncName" , outputBindings ) ;
372+
373+ powerShellManagerPool . ReclaimUsedWorker ( worker ) ;
374+ }
375+
361376 private static Hashtable InvokeFunction ( PowerShellManager powerShellManager , AzFunctionInfo functionInfo , Hashtable triggerMetadata = null )
362377 {
363378 return powerShellManager . InvokeFunction ( functionInfo , triggerMetadata , null , s_testInputData , new FunctionInvocationPerformanceStopwatch ( ) ) ;
364379 }
380+
381+ private class ContextValidatingLogger : ILogger
382+ {
383+ private bool _isContextSet = false ;
384+
385+ public void Log ( bool isUserOnlyLog , RpcLog . Types . Level logLevel , string message , Exception exception = null )
386+ {
387+ Assert . True ( _isContextSet ) ;
388+ }
389+
390+ public void SetContext ( string requestId , string invocationId )
391+ {
392+ _isContextSet = true ;
393+ }
394+
395+ public void ResetContext ( )
396+ {
397+ _isContextSet = false ;
398+ }
399+ }
365400 }
366401}
0 commit comments