Skip to content

Commit 06f4f13

Browse files
authored
don't report communication error on discovery abort (#14992)
* don't report communication error on discovery abort * revert
1 parent 2b36dc5 commit 06f4f13

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,25 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
196196

197197
private void HandleException(Exception exception)
198198
{
199-
EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);
199+
// 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.
200+
// In such case don't report the exception because user cannot do anything about it.
201+
if (!(_proxyOperationManager != null && _proxyOperationManager.CancellationTokenSource.IsCancellationRequested && exception is CommunicationException))
202+
{
203+
EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);
200204

201-
// Log to vs ide test output
202-
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() };
203-
var rawMessage = _dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
204-
HandleRawMessage(rawMessage);
205+
// Log to vs ide test output
206+
var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() };
207+
var rawMessage = _dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
208+
HandleRawMessage(rawMessage);
209+
210+
// Log to vstest.console
211+
HandleLogMessage(TestMessageLevel.Error, exception.ToString());
212+
}
205213

206-
// Log to vstest.console
207214
// Send a discovery complete to caller. Similar logic is also used in ParallelProxyDiscoveryManager.DiscoverTestsOnConcurrentManager
208215
// Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager
209216
// created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error
210217
// and the test host is lost as well.
211-
HandleLogMessage(TestMessageLevel.Error, exception.ToString());
212-
213218
var discoveryCompletePayload = new DiscoveryCompletePayload
214219
{
215220
IsAborted = true,

0 commit comments

Comments
 (0)