private bool RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar) { // Make sure to run the run request inside a lock as the below section is not thread-safe // TranslationLayer can process faster as it directly gets the raw unserialized messages whereas // below logic needs to deserialize and do some cleanup // While this section is cleaning up, TranslationLayer can trigger run causing multiple threads to run the below section at the same time lock (syncobject) { bool success = true; try { using (ITestRunRequest testRunRequest = this.testPlatform.CreateTestRunRequest(requestData, testRunCriteria)) { this.currentTestRunRequest = testRunRequest; this.runRequestCreatedEventHandle.Set(); try { this.testLoggerManager.RegisterTestRunEvents(testRunRequest); this.testRunResultAggregator.RegisterTestRunEvents(testRunRequest); testRunEventsRegistrar?.RegisterTestRunEvents(testRunRequest); this.testPlatformEventSource.ExecutionRequestStart(); testRunRequest.ExecuteAsync(); // Wait for the run completion event testRunRequest.WaitForCompletion(); } finally { this.testLoggerManager.UnregisterTestRunEvents(testRunRequest); this.testRunResultAggregator.UnregisterTestRunEvents(testRunRequest); testRunEventsRegistrar?.UnregisterTestRunEvents(testRunRequest); } } } catch (Exception ex) { EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex); if (ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) { LoggerUtilities.RaiseTestRunError(this.testLoggerManager, this.testRunResultAggregator, ex); success = false; } else { throw; } } this.currentTestRunRequest = null; return(success); } }
private void RunTests( IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar, TestPlatformOptions options) { // Make sure to run the run request inside a lock as the below section is not thread-safe. // TranslationLayer can process faster as it directly gets the raw un-serialized messages // whereas below logic needs to deserialize and do some cleanup. // While this section is cleaning up, TranslationLayer can trigger run causing multiple // threads to run the below section at the same time. lock (this.syncObject) { try { this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest( requestData, testRunCriteria, options); this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest); ((Microsoft.VisualStudio.TestPlatform.Client.TestPlatform) this.testPlatform).VStestLoggerManager = this.VSTestLoggerManager; this.TestPlatformEventSourceInstance.ExecutionRequestStart(); this.currentTestRunRequest.ExecuteAsync(); // Wait for the run completion event this.currentTestRunRequest.WaitForCompletion(); } catch (Exception ex) { EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex); testRunResultAggregator.MarkTestRunFailed(); throw; } finally { if (this.currentTestRunRequest != null) { this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); this.currentTestRunRequest.Dispose(); this.currentTestRunRequest = null; } } } }
private bool RunTests(TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar) { bool success = true; using (this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(testRunCriteria)) { this.runRequestCreatedEventHandle.Set(); try { this.testLoggerManager.RegisterTestRunEvents(this.currentTestRunRequest); this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest); this.testPlatformEventSource.ExecutionRequestStart(); this.currentTestRunRequest.ExecuteAsync(); // Wait for the run completion event this.currentTestRunRequest.WaitForCompletion(); this.testPlatformEventSource.ExecutionRequestStop(); } catch (Exception ex) { if (ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) { LoggerUtilities.RaiseTestRunError(this.testLoggerManager, this.testRunResultAggregator, ex); success = false; } else { throw; } } finally { this.testLoggerManager.UnregisterTestRunEvents(this.currentTestRunRequest); this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); } } this.currentTestRunRequest = null; return(success); }
private void RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar) { // Make sure to run the run request inside a lock as the below section is not thread-safe // TranslationLayer can process faster as it directly gets the raw unserialized messages whereas // below logic needs to deserialize and do some cleanup // While this section is cleaning up, TranslationLayer can trigger run causing multiple threads to run the below section at the same time lock (syncobject) { try { this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(requestData, testRunCriteria); this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest); this.testPlatformEventSource.ExecutionRequestStart(); this.currentTestRunRequest.ExecuteAsync(); this.runRequestStartedEventHandle.Set(); // Wait for the run completion event this.currentTestRunRequest.WaitForCompletion(); } catch (Exception ex) { EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex); testRunResultAggregator.MarkTestRunFailed(); throw; } finally { if (this.currentTestRunRequest != null) { this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); this.currentTestRunRequest.Dispose(); this.currentTestRunRequest = null; } } } }