-
Notifications
You must be signed in to change notification settings - Fork 324
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
Migrate DateTime.Now to DateTime.UtcNow to make sure all test reporti… #1612
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,8 @@ public TestResult(TestCase testCase) | |
|
||
// Default start and end time values for a test result are initialized to current timestamp | ||
// to maintain compatibility. | ||
this.StartTime = DateTimeOffset.Now; | ||
this.EndTime = DateTimeOffset.Now; | ||
this.StartTime = DateTimeOffset.UtcNow; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could change the behavior for inner loop scenarios. If any client displaying time it's client responsibility to localize the date. TestPlatform will use UTC for consistence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed, it might be. But we need to draw this and follow everywhere as UTC standard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Totally agreed. |
||
this.EndTime = DateTimeOffset.UtcNow; | ||
} | ||
|
||
#endregion | ||
|
@@ -255,10 +255,10 @@ protected override void ProtectedSetPropertyValue(TestProperty property, object | |
public class TestResultMessage | ||
{ | ||
// Bugfix: 297759 Moving the category from the resources to the code | ||
// so that it works on machines which has eng OS & non-eng VS and vice versa. | ||
// so that it works on machines which has eng OS & non-eng VS and vice versa. | ||
|
||
/// <summary> | ||
/// Standard Output Message Category | ||
/// Standard Output Message Category | ||
/// </summary> | ||
public static readonly string StandardOutCategory = "StdOutMsgs"; | ||
|
||
|
@@ -278,7 +278,7 @@ public class TestResultMessage | |
public static readonly string AdditionalInfoCategory = "AdtnlInfo"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TestResultMessage"/> class. | ||
/// Initializes a new instance of the <see cref="TestResultMessage"/> class. | ||
/// </summary> | ||
/// <param name="category">Category of the message.</param> | ||
/// <param name="text">Text of the message.</param> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Xml.Linq; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This should go under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
namespace Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests | ||
{ | ||
using System; | ||
|
@@ -692,6 +694,35 @@ public void CRLFCharactersShouldGetRetainedInTrx() | |
Assert.IsTrue(string.Equals(message, actualMessage), string.Format("StdOut messages do not match. Expected:{0}, Actual:{1}", message, actualMessage)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRunInformationShouldContainUtcDateTime() | ||
{ | ||
this.MakeTestRunComplete(); | ||
this.ValidateDateTimeInTrx(this.testableTrxLogger.trxFile); | ||
} | ||
|
||
private void ValidateDateTimeInTrx(string trxFileName) | ||
{ | ||
using (FileStream file = File.OpenRead(trxFileName)) | ||
{ | ||
using (XmlReader reader = XmlReader.Create(file)) | ||
{ | ||
XDocument document = XDocument.Load(reader); | ||
var timesNode = document.Descendants(document.Root.GetDefaultNamespace() + "Times").FirstOrDefault(); | ||
ValidateTimeWithinUtcLimits(DateTimeOffset.Parse(timesNode.Attributes("creation").FirstOrDefault().Value)); | ||
ValidateTimeWithinUtcLimits(DateTimeOffset.Parse(timesNode.Attributes("start").FirstOrDefault().Value)); | ||
var resultNode = document.Descendants(document.Root.GetDefaultNamespace() + "UnitTestResult").FirstOrDefault(); | ||
ValidateTimeWithinUtcLimits(DateTimeOffset.Parse(resultNode.Attributes("endTime").FirstOrDefault().Value)); | ||
ValidateTimeWithinUtcLimits(DateTimeOffset.Parse(resultNode.Attributes("startTime").FirstOrDefault().Value)); | ||
} | ||
} | ||
} | ||
|
||
private void ValidateTimeWithinUtcLimits(DateTimeOffset dateTime) | ||
{ | ||
Assert.IsTrue(dateTime.UtcDateTime.Subtract(DateTime.UtcNow) < new TimeSpan(0, 0, 0, 60)); | ||
} | ||
|
||
private string GetElementValueFromTrx(string trxFileName, string fieldName) | ||
{ | ||
using (FileStream file = File.OpenRead(trxFileName)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done