@@ -18,14 +18,14 @@ internal class LoggerQueue
1818 private readonly Task _consumeTask ;
1919 private readonly CancellationTokenSource _consumeTaskCancellationSource = new CancellationTokenSource ( ) ;
2020
21-
2221 private readonly IApiClient _apiClient ;
2322 private readonly string _buildId ;
2423 private readonly string _agentName ;
2524 private readonly string _jobName ;
2625
2726 // Internal for testing
2827 internal Dictionary < string , TestResultParent > Parents { get ; } = new Dictionary < string , TestResultParent > ( ) ;
28+ internal DateTime StartedDate { get ; } = DateTime . UtcNow ;
2929 internal int RunId { get ; set ; }
3030 internal string Source { get ; set ; }
3131 internal string TestRunEndpoint { get ; set ; }
@@ -139,6 +139,7 @@ internal async Task<int> CreateTestRun(CancellationToken cancellationToken)
139139 {
140140 { "name" , runName } ,
141141 { "build" , new Dictionary < string , object > { { "id" , _buildId } } } ,
142+ { "startedDate" , StartedDate . ToString ( "yyyy-MM-ddTHH:mm:ss.FFFZ" ) } ,
142143 { "isAutomated" , true }
143144 } ;
144145 string responseString = await _apiClient . SendAsync ( HttpMethod . Post , null , "5.0-preview.2" , request . ToJson ( ) , cancellationToken ) ;
@@ -179,6 +180,7 @@ internal async Task CreateParents(IEnumerable<IGrouping<string, ITestResult>> te
179180 . ToArray ( ) ;
180181
181182 // Batch an add operation and record the new parent IDs
183+ DateTime startedDate = DateTime . UtcNow ;
182184 if ( parentsToAdd . Length > 0 )
183185 {
184186 string request = "[ " + string . Join ( ", " , parentsToAdd . Select ( x =>
@@ -190,6 +192,7 @@ internal async Task CreateParents(IEnumerable<IGrouping<string, ITestResult>> te
190192 { "resultGroupType" , "generic" } ,
191193 { "outcome" , "Passed" } , // Start with a passed outcome initially
192194 { "state" , "InProgress" } ,
195+ { "startedDate" , startedDate . ToString ( "yyyy-MM-ddTHH:mm:ss.FFFZ" ) } ,
193196 { "automatedTestType" , "UnitTest" } ,
194197 { "automatedTestTypeId" , "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" } // This is used in the sample response and also appears in web searches
195198 } ;
@@ -211,7 +214,7 @@ internal async Task CreateParents(IEnumerable<IGrouping<string, ITestResult>> te
211214 for ( int c = 0 ; c < parents . Length ; c ++ )
212215 {
213216 int id = ( ( JsonObject ) parents [ c ] ) . ValueAsInt ( "id" ) ;
214- Parents . Add ( parentsToAdd [ c ] , new TestResultParent ( id ) ) ;
217+ Parents . Add ( parentsToAdd [ c ] , new TestResultParent ( id , startedDate ) ) ;
215218 }
216219 }
217220 }
@@ -285,19 +288,20 @@ private string GetTestResultJson(ITestResult testResult)
285288
286289 private async Task SendTestsCompleted ( CancellationToken cancellationToken )
287290 {
291+ string completedDate = DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:ss.FFFZ" ) ;
288292 // Mark all parents as completed
289293 string parentRequest = "[ " + string . Join ( ", " , Parents . Values . Select ( x =>
290294 $@ "{{
291295 ""id"": { x . Id } ,
292296 ""state"": ""Completed"",
293- ""completedDate"": ""{ DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:ss.FFFZ" ) } ""
297+ ""completedDate"": ""{ completedDate } ""
294298 }}" ) ) + " ]" ;
295299 await _apiClient . SendAsync ( new HttpMethod ( "PATCH" ) , TestRunEndpoint , "5.0-preview.5" , parentRequest , cancellationToken ) ;
296300
297301 // Mark the overall test run as completed
298302 string testRunRequest = $@ "{{
299303 ""state"": ""Completed"",
300- ""completedDate"": ""{ DateTime . UtcNow . ToString ( "yyyy-MM-ddTHH:mm:ss.FFFZ" ) } ""
304+ ""completedDate"": ""{ completedDate } ""
301305 }}" ;
302306 await _apiClient . SendAsync ( new HttpMethod ( "PATCH" ) , $ "/{ RunId } ", "5.0-preview.2" , testRunRequest , cancellationToken ) ;
303307 }
0 commit comments