/// <inheritdoc/> public void RunTestsWithCustomTestHost( IEnumerable <string> sources, string runSettings, TestPlatformOptions options, TestSessionInfo testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { var sourceList = sources.ToList(); this.testPlatformEventSource.TranslationLayerExecutionStart( 1, sourceList.Count, 0, runSettings ?? string.Empty); this.EnsureInitialized(); this.requestSender.StartTestRunWithCustomHost( sourceList, runSettings, options, testSessionInfo, testRunEventsHandler, customTestHostLauncher); }
/// <inheritdoc/> public async Task RunTestsWithCustomTestHostAsync( IEnumerable <TestCase> testCases, string runSettings, TestPlatformOptions options, TestSessionInfo testSessionInfo, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) { var testCaseList = testCases.ToList(); this.testPlatformEventSource.TranslationLayerExecutionStart( 1, 0, testCaseList.Count, runSettings ?? string.Empty); await this.EnsureInitializedAsync(); await this.requestSender.StartTestRunWithCustomHostAsync( testCaseList, runSettings, options, testSessionInfo, testRunEventsHandler, customTestHostLauncher); }
/// <summary> /// Initializes a new instance of the <see cref="TestSession"/> class. /// </summary> /// /// <param name="testSessionInfo">The test session info object.</param> /// <param name="consoleWrapper">The encapsulated console wrapper.</param> public TestSession( TestSessionInfo testSessionInfo, VsTestConsoleWrapper consoleWrapper) { this.testSessionInfo = testSessionInfo; this.consoleWrapper = consoleWrapper; }
/// <summary> /// Returns the proxy object to the session pool. /// </summary> /// /// <param name="testSessionInfo">The test session info object.</param> /// <param name="proxyId">The proxy id to be returned.</param> public void ReturnProxy(TestSessionInfo testSessionInfo, Guid proxyId) { ProxyTestSessionManager sessionManager = null; lock (this.lockObject) { // Gets the session manager reference from the pool. sessionManager = this.sessionPool[testSessionInfo]; } try { // Try re-enqueueing the specified proxy. sessionManager.EnqueueProxy(proxyId); } catch (InvalidOperationException ex) { // If we are unable to re-enqueue the proxy we just eat up the exception here as // it is safe to proceed. // // WARNING: This should not normally happen and it raises questions regarding the // test session pool operation and consistency. EqtTrace.Warning("TestSessionPool.ReturnProxy failed: {0}", ex.ToString()); } }
/// <inheritdoc /> public void HandleStartTestSessionComplete(TestSessionInfo testSessionInfo) { var ackPayload = new StartTestSessionAckPayload() { TestSessionInfo = testSessionInfo }; this.communicationManager.SendMessage(MessageType.StartTestSessionCallback, ackPayload); }
/// <inheritdoc /> public void HandleStopTestSessionComplete(TestSessionInfo testSessionInfo, bool stopped) { var ackPayload = new StopTestSessionAckPayload() { TestSessionInfo = testSessionInfo, IsStopped = stopped }; this.communicationManager.SendMessage(MessageType.StopTestSessionCallback, ackPayload); }
/// <inheritdoc/> public bool StopTestSession( TestSessionInfo testSessionInfo, ITestSessionEventsHandler eventsHandler) { this.testPlatformEventSource.TranslationLayerStopTestSessionStart(); this.EnsureInitialized(); return(this.requestSender.StopTestSession( testSessionInfo, eventsHandler)); }
/// <inheritdoc/> public async Task <bool> StopTestSessionAsync( TestSessionInfo testSessionInfo, ITestSessionEventsHandler eventsHandler) { this.testPlatformEventSource.TranslationLayerStopTestSessionStart(); await this.EnsureInitializedAsync().ConfigureAwait(false); return(await this.requestSender.StopTestSessionAsync( testSessionInfo, eventsHandler).ConfigureAwait(false)); }
/// <summary> /// Initializes a new instance of the <see cref="ProxyExecutionManager"/> class. /// </summary> /// /// <param name="testSessionInfo">The test session info.</param> /// <param name="debugEnabledForTestSession"> /// A flag indicating if debugging should be enabled or not. /// </param> public ProxyExecutionManager(TestSessionInfo testSessionInfo, bool debugEnabledForTestSession) { // Filling in test session info and proxy information. this.testSessionInfo = testSessionInfo; this.ProxyOperationManager = TestSessionPool.Instance.TakeProxy(this.testSessionInfo); // This should be set to enable debugging when we have test session info available. this.debugEnabledForTestSession = debugEnabledForTestSession; this.testHostManager = this.ProxyOperationManager.TestHostManager; this.dataSerializer = JsonDataSerializer.Instance; this.isCommunicationEstablished = false; this.requestData = this.ProxyOperationManager.RequestData; this.fileHelper = new FileHelper(); }
/// <summary> /// Gets a reference to the proxy object from the session pool. /// </summary> /// /// <param name="testSessionInfo">The test session info object.</param> /// /// <returns>The proxy object.</returns> public ProxyOperationManager TakeProxy(TestSessionInfo testSessionInfo) { ProxyTestSessionManager sessionManager = null; lock (this.lockObject) { // Gets the session manager reference from the pool. sessionManager = this.sessionPool[testSessionInfo]; } // Deque an actual proxy to do work. // // This can potentially throw, but let the caller handle this as it must recover from // this error by creating its own proxy. return(sessionManager.DequeueProxy()); }
/// <inheritdoc/> public void DiscoverTests( IEnumerable <string> sources, string discoverySettings, TestPlatformOptions options, TestSessionInfo testSessionInfo, ITestDiscoveryEventsHandler2 discoveryEventsHandler) { this.testPlatformEventSource.TranslationLayerDiscoveryStart(); this.EnsureInitialized(); // TODO (copoiena): Add session info as a parameter. this.requestSender.DiscoverTests( sources, discoverySettings, options, discoveryEventsHandler); }
/// <summary> /// Adds a session to the pool. /// </summary> /// /// <param name="testSessionInfo">The test session info object.</param> /// <param name="proxyManager">The proxy manager object.</param> /// /// <returns>True if the operation succeeded, false otherwise.</returns> public bool AddSession( TestSessionInfo testSessionInfo, ProxyTestSessionManager proxyManager) { lock (this.lockObject) { // Check if the session info already exists. if (this.sessionPool.ContainsKey(testSessionInfo)) { return(false); } // Adds an association between session info and proxy manager to the pool. this.sessionPool.Add(testSessionInfo, proxyManager); return(true); } }
private void StopTestSession(TestSessionInfo testSessionInfo) { Task.Run(() => { var eventsHandler = new TestSessionEventsHandler(this.communicationManager); try { var stopped = TestSessionPool.Instance.KillSession(testSessionInfo); eventsHandler.HandleStopTestSessionComplete(testSessionInfo, stopped); } catch (Exception ex) { EqtTrace.Error("DesignModeClient: Exception in StopTestSession: " + ex); eventsHandler.HandleLogMessage(TestMessageLevel.Error, ex.ToString()); eventsHandler.HandleStopTestSessionComplete(testSessionInfo, false); } }); }
/// <summary> /// Kills and removes a session from the pool. /// </summary> /// /// <param name="testSessionInfo">The test session info object.</param> /// /// <returns>True if the operation succeeded, false otherwise.</returns> public bool KillSession(TestSessionInfo testSessionInfo) { // TODO (copoiena): What happens if some request is running for the current session ? // Should we stop the request as well ? Probably yes. ProxyTestSessionManager proxyManager = null; lock (this.lockObject) { // Check if the session info exists. if (!this.sessionPool.ContainsKey(testSessionInfo)) { return(false); } // Remove the session from the pool. proxyManager = this.sessionPool[testSessionInfo]; this.sessionPool.Remove(testSessionInfo); } // Kill the session. proxyManager.StopSession(); return(true); }
/// <inheritdoc/> public void RunTests( IEnumerable <TestCase> testCases, string runSettings, TestPlatformOptions options, TestSessionInfo testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var testCaseList = testCases.ToList(); this.testPlatformEventSource.TranslationLayerExecutionStart( 0, 0, testCaseList.Count, runSettings ?? string.Empty); this.EnsureInitialized(); this.requestSender.StartTestRun( testCaseList, runSettings, options, testSessionInfo, testRunEventsHandler); }
/// <inheritdoc/> public void StartSession( StartTestSessionCriteria criteria, ITestSessionEventsHandler eventsHandler) { var testSessionInfo = new TestSessionInfo(); Task[] taskList = new Task[this.parallelLevel]; // Create all the proxies in parallel, one task per proxy. for (int i = 0; i < this.parallelLevel; ++i) { taskList[i] = Task.Factory.StartNew(() => { // Create the proxy. var operationManagerProxy = this.CreateProxy(); // Initialize the proxy. operationManagerProxy.Initialize(this.skipDefaultAdapters); // Start the test host associated to the proxy. operationManagerProxy.SetupChannel( criteria.Sources, criteria.RunSettings, eventsHandler); }); } // Wait for proxy creation to be over. Task.WaitAll(taskList); // Make the session available. TestSessionPool.Instance.AddSession(testSessionInfo, this); // Let the caller know the session has been created. eventsHandler.HandleStartTestSessionComplete(testSessionInfo); }
/// <inheritdoc/> public async Task RunTestsAsync( IEnumerable <string> sources, string runSettings, TestPlatformOptions options, TestSessionInfo testSessionInfo, ITestRunEventsHandler testRunEventsHandler) { var sourceList = sources.ToList(); this.testPlatformEventSource.TranslationLayerExecutionStart( 0, sourceList.Count, 0, runSettings ?? string.Empty); await this.EnsureInitializedAsync(); await this.requestSender.StartTestRunAsync( sourceList, runSettings, options, testSessionInfo, testRunEventsHandler); }