Skip to content

Commit

Permalink
don't report communication error on discovery abort (#14992)
Browse files Browse the repository at this point in the history
* don't report communication error on discovery abort

* revert
  • Loading branch information
nohwnd authored Jan 28, 2025
1 parent 2b36dc5 commit 06f4f13
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,25 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve

private void HandleException(Exception exception)
{
EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);
// If requested abort and the code below was just sending data, we will get communication exception because we try to write the channel that is already closed.
// In such case don't report the exception because user cannot do anything about it.
if (!(_proxyOperationManager != null && _proxyOperationManager.CancellationTokenSource.IsCancellationRequested && exception is CommunicationException))
{
EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);

// Log to vs ide test output
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() };
var rawMessage = _dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
HandleRawMessage(rawMessage);
// Log to vs ide test output
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() };
var rawMessage = _dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
HandleRawMessage(rawMessage);

// Log to vstest.console
HandleLogMessage(TestMessageLevel.Error, exception.ToString());
}

// Log to vstest.console
// Send a discovery complete to caller. Similar logic is also used in ParallelProxyDiscoveryManager.DiscoverTestsOnConcurrentManager
// Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager
// created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error
// and the test host is lost as well.
HandleLogMessage(TestMessageLevel.Error, exception.ToString());

var discoveryCompletePayload = new DiscoveryCompletePayload
{
IsAborted = true,
Expand Down

0 comments on commit 06f4f13

Please sign in to comment.