-
Notifications
You must be signed in to change notification settings - Fork 323
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
Fix Few UWP VC++ unit tests are not executing #1649
Changes from 2 commits
6b563d8
658fa5c
005d4ff
4830785
e06d0df
b917d81
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 |
---|---|---|
|
@@ -152,6 +152,13 @@ public string SerializePayload(string messageType, object payload, int version) | |
return JsonConvert.SerializeObject(message); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public T Clone<T>(T obj) | ||
{ | ||
var stringObj = this.Serialize<T>(obj); | ||
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. Suggestion: Check for ICloneable implemention and if so use it. else fallback 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. Please see #1649 (comment) |
||
return this.Deserialize<T>(stringObj); | ||
} | ||
|
||
/// <summary> | ||
/// Serialize an object to JSON using default serialization settings. | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,7 +571,7 @@ private void RaiseTestRunComplete( | |
testRunCompleteEventArgs.Metrics = this.requestData.MetricsCollection.Metrics; | ||
if (lastChunk.Any()) | ||
{ | ||
UpdateTestResults(lastChunk, null, this.package); | ||
UpdateTestResultsAndInProgressTests(lastChunk, null, this.package); | ||
} | ||
|
||
this.testRunEventsHandler.HandleTestRunComplete( | ||
|
@@ -586,13 +586,13 @@ private void RaiseTestRunComplete( | |
} | ||
} | ||
|
||
private void OnCacheHit(TestRunStatistics testRunStats, ICollection<TestResult> results, ICollection<TestCase> inProgressTests) | ||
private void OnCacheHit(TestRunStatistics testRunStats, ICollection<TestResult> results, ICollection<TestCase> inProgressTestCases) | ||
{ | ||
if (this.testRunEventsHandler != null) | ||
{ | ||
UpdateTestResults(results, inProgressTests, this.package); | ||
inProgressTestCases = UpdateTestResultsAndInProgressTests(results, inProgressTestCases, this.package); | ||
|
||
var testRunChangedEventArgs = new TestRunChangedEventArgs(testRunStats, results, inProgressTests); | ||
var testRunChangedEventArgs = new TestRunChangedEventArgs(testRunStats, results, inProgressTestCases); | ||
this.testRunEventsHandler.HandleTestRunStatsChange(testRunChangedEventArgs); | ||
} | ||
else | ||
|
@@ -624,22 +624,44 @@ private bool TryToRunInSTAThread(Action action, bool waitForCompletion) | |
} | ||
|
||
|
||
private static void UpdateTestResults(IEnumerable<TestResult> testResults, IEnumerable<TestCase> testCases, string package) | ||
private static ICollection<TestCase> UpdateTestResultsAndInProgressTests(IEnumerable<TestResult> testResults, ICollection<TestCase> inProgressTestCases, string package) | ||
{ | ||
|
||
// No change required to testcases and testresults. | ||
if (string.IsNullOrEmpty(package)) | ||
{ | ||
return inProgressTestCases; | ||
} | ||
|
||
EqtTrace.Verbose("BaseRunTests.UpdateTestResultsAndInProgressTests: Update source details for testResults and testCases."); | ||
|
||
// Before sending the testresults back, update the test case objects with source provided by IDE/User. | ||
if (!string.IsNullOrEmpty(package)) | ||
foreach (var tr in testResults) | ||
{ | ||
foreach (var tr in testResults) | ||
{ | ||
tr.TestCase.Source = package; | ||
} | ||
tr.TestCase.Source = package; | ||
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.
Is this safe ? 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. No, this not safe. As we discussed offline, currently there is no known scenario to which break because of not copying(better performance). However it is better to copy the test results(which adapter creates) to make sure correctness over performance. I have made changes to copy the test results too. |
||
} | ||
|
||
// TestCases can be empty, enumerate on EmptyList then | ||
foreach (var tc in testCases ?? Enumerable.Empty<TestCase>()) | ||
{ | ||
tc.Source = package; | ||
} | ||
return UpdateInProgressTests(inProgressTestCases, package); | ||
} | ||
|
||
private static ICollection<TestCase> UpdateInProgressTests(ICollection<TestCase> inProgressTestCases, string package) | ||
{ | ||
if (inProgressTestCases == null) | ||
{ | ||
return null; | ||
} | ||
|
||
EqtTrace.Verbose("BaseRunTests.UpdateInProgressTests: Updating source for inprogress tests."); | ||
|
||
ICollection<TestCase> updatedTestCases = new List<TestCase>(); | ||
foreach (var inProgressTestCase in inProgressTestCases) | ||
{ | ||
var updatedTestCase = JsonDataSerializer.Instance.Clone<TestCase>(inProgressTestCase); | ||
updatedTestCase.Source = package; | ||
updatedTestCases.Add(updatedTestCase); | ||
} | ||
|
||
return updatedTestCases; | ||
} | ||
|
||
#endregion | ||
|
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.
Please write a comment on why we chose this approach, just for reference.
Also consider making it an extension method.
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.
There are lot of discussion over stackoverflow, how to do deep copy.
This very generic and easy to implement, But it is not available in NS14.
This required changes in all the class which are involved and difficult to maintain(complicated code).
As we are already using
JsonDataSeializer
to transfer the object over network. We can use the same functionality to do clone Which is well tested.