33
44using System . Runtime . Serialization ;
55using Microsoft . DurableTask . Client ;
6+ using Microsoft . DurableTask . Tests . Logging ;
67using Microsoft . DurableTask . Worker ;
78using Xunit . Abstractions ;
89using Xunit . Sdk ;
@@ -28,8 +29,11 @@ public async Task UnhandledActivityException()
2829 TaskName activityName = "FaultyActivity" ;
2930
3031 // Use local function definitions to simplify the validation of the call stacks
31- async Task MyOrchestrationImpl ( TaskOrchestrationContext ctx ) => await ctx . CallActivityAsync ( activityName ) ;
32- void MyActivityImpl ( TaskActivityContext ctx ) => throw new Exception ( errorMessage , new CustomException ( "Inner!" ) ) ;
32+ async Task MyOrchestrationImpl ( TaskOrchestrationContext ctx ) =>
33+ await ctx . CallActivityAsync ( activityName ) ;
34+
35+ void MyActivityImpl ( TaskActivityContext ctx ) =>
36+ throw new InvalidOperationException ( errorMessage , new CustomException ( "Inner!" ) ) ;
3337
3438 await using HostTestLifetime server = await this . StartWorkerAsync ( b =>
3539 {
@@ -64,13 +68,45 @@ public async Task UnhandledActivityException()
6468
6569 // Check that the inner exception - i.e. the exact exception that failed the orchestration - was populated correctly
6670 Assert . NotNull ( failureDetails . InnerFailure ) ;
67- Assert . Equal ( typeof ( Exception ) . FullName , failureDetails . InnerFailure ! . ErrorType ) ;
71+ Assert . Equal ( typeof ( InvalidOperationException ) . FullName , failureDetails . InnerFailure ! . ErrorType ) ;
6872 Assert . Equal ( errorMessage , failureDetails . InnerFailure . ErrorMessage ) ;
6973
7074 // Check that the inner-most exception was populated correctly too (the custom exception type)
7175 Assert . NotNull ( failureDetails . InnerFailure . InnerFailure ) ;
7276 Assert . Equal ( typeof ( CustomException ) . FullName , failureDetails . InnerFailure . InnerFailure ! . ErrorType ) ;
7377 Assert . Equal ( "Inner!" , failureDetails . InnerFailure . InnerFailure . ErrorMessage ) ;
78+
79+ IReadOnlyCollection < LogEntry > workerLogs = this . GetLogs ( category : "Microsoft.DurableTask.Worker" ) ;
80+ Assert . NotEmpty ( workerLogs ) ;
81+
82+ // Check that the orchestrator and activity logs are present
83+ Assert . Single ( workerLogs , log => MatchLog (
84+ log ,
85+ logEventName : "OrchestrationStarted" ,
86+ exception : null ,
87+ ( "InstanceId" , instanceId ) ,
88+ ( "Name" , orchestratorName . Name ) ) ) ;
89+
90+ Assert . Single ( workerLogs , log => MatchLog (
91+ log ,
92+ logEventName : "ActivityStarted" ,
93+ exception : null ,
94+ ( "InstanceId" , instanceId ) ,
95+ ( "Name" , activityName . Name ) ) ) ;
96+
97+ Assert . Single ( workerLogs , log => MatchLog (
98+ log ,
99+ logEventName : "ActivityFailed" ,
100+ exception : ( typeof ( InvalidOperationException ) , errorMessage ) ,
101+ ( "InstanceId" , instanceId ) ,
102+ ( "Name" , activityName . Name ) ) ) ;
103+
104+ Assert . Single ( workerLogs , log => MatchLog (
105+ log ,
106+ logEventName : "OrchestrationFailed" ,
107+ exception : ( typeof ( TaskFailedException ) , $ "Task '{ activityName } ' (#0) failed with an unhandled exception: { errorMessage } ") ,
108+ ( "InstanceId" , instanceId ) ,
109+ ( "Name" , orchestratorName . Name ) ) ) ;
74110 }
75111
76112 /// <summary>
0 commit comments