How to use TestRuntimeProviderInfo method of Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.TestRuntimeProviderInfo class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.TestRuntimeProviderInfo.TestRuntimeProviderInfo

TestEngine.cs

Source:TestEngine.cs Github

copy

Full Screen

...70 // Collecting IsParallel enabled.71 requestData.MetricsCollection.Add(TelemetryDataConstants.ParallelEnabledDuringDiscovery, isParallelRun ? "True" : "False");72 requestData.MetricsCollection.Add(TelemetryDataConstants.TestSessionId, discoveryCriteria.TestSessionInfo?.Id.ToString() ?? string.Empty);73 // Get testhost managers by configuration, and either use it for in-process run. or for single source run.74 List<TestRuntimeProviderInfo> testHostManagers = GetTestRuntimeProvidersForUniqueConfigurations(discoveryCriteria.RunSettings!, sourceToSourceDetailMap, warningLogger, out ITestRuntimeProvider? testHostManager);75 // This is a big if that figures out if we can run in process. In process run is very restricted, it is non-parallel run76 // that has the same target framework as the current process, and it also must not be running in DesignMode (server mode / under IDE)77 // and more conditions. In all other cases we run in a separate testhost process.78 if (ShouldRunInProcess(discoveryCriteria.RunSettings!, isParallelRun, isDataCollectorEnabled: false, testHostManagers))79 {80 // We are running in process, so whatever the architecture and framework that was figured out is, it must be compatible. If we have more81 // changes that we want to do to runsettings in the future, based on SourceDetail then it will depend on those details. But in general82 // we will have to check that all source details are the same. Otherwise we for sure cannot run in process.83 // E.g. if we get list of sources where one of them has different architecture we for sure cannot run in process, because the current84 // process can handle only single runsettings.85 if (testHostManagers.Count != 1)86 {87 throw new InvalidOperationException($"Exactly 1 testhost manager must be provided when running in process, but there {testHostManagers.Count} were provided.");88 }89 var testHostManagerInfo = testHostManagers[0];90 TPDebug.Assert(testHostManager is not null, "testHostManager is null");91 // Don't intialize, we are taking an instance that we created already initialized in GetTestRuntimeProvidersForUniqueConfigurations92 // testHostManager.Initialize(TestSessionMessageLogger.Instance, testHostManagerInfo.RunSettings);93 return new InProcessProxyDiscoveryManager(94 testHostManager,95 new TestHostManagerFactory(requestData.IsTelemetryOptedIn));96 }97 // Create one data aggregator per parallel discovery and share it with all the proxy discovery managers.98 // We need to share the aggregator because when cancelling discovery we don't want to await all managers,99 // and so the first manager replying with the discovery complete (aborted) event arg will cause the parallel100 // discovery manager to publish its current state. But doing so we are losing the collected state of all the101 // other managers.102 var discoveryDataAggregator = new DiscoveryDataAggregator();103 Func<TestRuntimeProviderInfo, IProxyDiscoveryManager> proxyDiscoveryManagerCreator = runtimeProviderInfo =>104 {105 var sources = runtimeProviderInfo.SourceDetails.Select(r => r.Source!).ToList();106 var hostManager = _testHostProviderManager.GetTestHostManagerByRunConfiguration(runtimeProviderInfo.RunSettings, sources);107 hostManager?.Initialize(TestSessionMessageLogger.Instance, runtimeProviderInfo.RunSettings!);108 ThrowExceptionIfTestHostManagerIsNull(hostManager, runtimeProviderInfo.RunSettings);109 TPDebug.Assert(hostManager is not null, "hostManager is null");110 // This function is used to either take a pre-existing proxy operation manager from111 // the test pool or to create a new proxy operation manager on the spot.112 Func<string, ProxyDiscoveryManager, ProxyOperationManager>113 proxyOperationManagerCreator = (114 string source,115 ProxyDiscoveryManager proxyDiscoveryManager) =>116 {117 TPDebug.Assert(discoveryCriteria.TestSessionInfo is not null, "discoveryCriteria.TestSessionInfo is null");118 // In case we have an active test session, we always prefer the already119 // created proxies instead of the ones that need to be created on the spot.120 var proxyOperationManager = TestSessionPool.Instance.TryTakeProxy(121 discoveryCriteria.TestSessionInfo,122 source,123 runtimeProviderInfo.RunSettings,124 requestData);125 if (proxyOperationManager == null)126 {127 // If the proxy creation process based on test session info failed, then128 // we'll proceed with the normal creation process as if no test session129 // info was passed in in the first place.130 //131 // WARNING: This should not normally happen and it raises questions132 // regarding the test session pool operation and consistency.133 EqtTrace.Warning("ProxyDiscoveryManager creation with test session failed.");134 proxyOperationManager = new ProxyOperationManager(135 requestData,136 new TestRequestSender(requestData.ProtocolConfig!, hostManager),137 hostManager,138 // There is always at least one, and all of them have the same framework and architecture.139 runtimeProviderInfo.SourceDetails[0].Framework,140 proxyDiscoveryManager);141 }142 return proxyOperationManager;143 };144 // In case we have an active test session, we always prefer the already145 // created proxies instead of the ones that need to be created on the spot.146 return (discoveryCriteria.TestSessionInfo != null)147 ? new ProxyDiscoveryManager(148 discoveryCriteria.TestSessionInfo,149 proxyOperationManagerCreator,150 discoveryDataAggregator)151 : new ProxyDiscoveryManager(152 requestData,153 new TestRequestSender(requestData.ProtocolConfig!, hostManager),154 hostManager,155 // There is always at least one, and all of them have the same framework and architecture.156 runtimeProviderInfo.SourceDetails[0].Framework,157 discoveryDataAggregator);158 };159 return new ParallelProxyDiscoveryManager(requestData, proxyDiscoveryManagerCreator, discoveryDataAggregator, parallelLevel, testHostManagers);160 }161 /// <inheritdoc/>162 public IProxyExecutionManager GetExecutionManager(163 IRequestData requestData,164 TestRunCriteria testRunCriteria,165 IDictionary<string, SourceDetail> sourceToSourceDetailMap,166 IWarningLogger warningLogger)167 {168 TPDebug.Assert(testRunCriteria.TestRunSettings is not null, "testRunCriteria.TestRunSettings is null");169 // We use mulitple "different" runsettings here. We have runsettings that come with the testRunCriteria,170 // and we use that to figure out the common stuff before we try to setup the run. Later we patch the settings171 // from the additional details that were passed. Those should not affect the common properties that are used for setup.172 // Right now the only two things that change there are the architecture and framework so we can mix them in a single run.173 var distinctSources = GetDistinctNumberOfSources(testRunCriteria);174 var parallelLevel = VerifyParallelSettingAndCalculateParallelLevel(distinctSources, testRunCriteria.TestRunSettings);175 // See comments in GetDiscoveryManager for more info about what is happening in this method.176 var isParallelRun = parallelLevel > 1;177 // Collecting IsParallel enabled.178 requestData.MetricsCollection.Add(TelemetryDataConstants.ParallelEnabledDuringExecution, isParallelRun ? "True" : "False");179 requestData.MetricsCollection.Add(TelemetryDataConstants.TestSessionId, testRunCriteria.TestSessionInfo?.Id.ToString() ?? string.Empty);180 var isDataCollectorEnabled = XmlRunSettingsUtilities.IsDataCollectionEnabled(testRunCriteria.TestRunSettings);181 var isInProcDataCollectorEnabled = XmlRunSettingsUtilities.IsInProcDataCollectionEnabled(testRunCriteria.TestRunSettings);182 var testHostProviders = GetTestRuntimeProvidersForUniqueConfigurations(testRunCriteria.TestRunSettings, sourceToSourceDetailMap, warningLogger, out ITestRuntimeProvider? testHostManager);183 if (ShouldRunInProcess(184 testRunCriteria.TestRunSettings,185 isParallelRun,186 isDataCollectorEnabled || isInProcDataCollectorEnabled,187 testHostProviders))188 {189 // Not updating runsettings from source detail on purpose here. We are running in process, so whatever the settings we figured out at the start. They must be compatible190 // with the current process, otherwise we would not be able to run inside of the current process.191 //192 // We know that we only have a single testHostManager here, because we figure that out in ShouldRunInProcess.193 ThrowExceptionIfTestHostManagerIsNull(testHostManager, testRunCriteria.TestRunSettings);194 TPDebug.Assert(testHostManager is not null, "testHostManager is null");195 // Don't intialize, we are taking an instance that we created already initialized in GetTestRuntimeProvidersForUniqueConfigurations196 // testHostManager.Initialize(TestSessionMessageLogger.Instance, testRunCriteria.TestRunSettings);197 // NOTE: The custom launcher should not be set when we have test session info available.198 if (testRunCriteria.TestHostLauncher != null)199 {200 testHostManager!.SetCustomLauncher(testRunCriteria.TestHostLauncher);201 }202 return new InProcessProxyExecutionManager(203 testHostManager,204 new TestHostManagerFactory(requestData.IsTelemetryOptedIn));205 }206 // This creates a single non-parallel execution manager, based requestData, isDataCollectorEnabled and the207 // overall testRunCriteria. The overall testRunCriteria are split to smaller pieces (e.g. each source from the overall208 // testRunCriteria) so we can run them in parallel, and those are then passed to those non-parallel execution managers.209 //210 // The function below grabs most of the parameter via closure from the local context,211 // but gets the runtime provider later, because that is specific info to the source (or sources) it will be running.212 // This creator does not get those smaller pieces of testRunCriteria, those come later when we call a method on213 // the non-parallel execution manager we create here. E.g. StartTests(<single piece of testRunCriteria>).214 Func<TestRuntimeProviderInfo, IProxyExecutionManager> proxyExecutionManagerCreator = runtimeProviderInfo =>215 CreateNonParallelExecutionManager(requestData, testRunCriteria, isDataCollectorEnabled, runtimeProviderInfo);216 var executionManager = new ParallelProxyExecutionManager(requestData, proxyExecutionManagerCreator, parallelLevel, testHostProviders);217 EqtTrace.Verbose($"TestEngine.GetExecutionManager: Chosen execution manager '{executionManager.GetType().AssemblyQualifiedName}' ParallelLevel '{parallelLevel}'.");218 return executionManager;219 }220 // This is internal so tests can use it.221 internal IProxyExecutionManager CreateNonParallelExecutionManager(IRequestData requestData, TestRunCriteria testRunCriteria, bool isDataCollectorEnabled, TestRuntimeProviderInfo runtimeProviderInfo)222 {223 // SetupChannel ProxyExecutionManager with data collection if data collectors are224 // specified in run settings.225 // Create a new host manager, to be associated with individual226 // ProxyExecutionManager(&POM)227 var sources = runtimeProviderInfo.SourceDetails.Select(r => r.Source!).ToList();228 var hostManager = _testHostProviderManager.GetTestHostManagerByRunConfiguration(runtimeProviderInfo.RunSettings, sources);229 ThrowExceptionIfTestHostManagerIsNull(hostManager, runtimeProviderInfo.RunSettings);230 hostManager!.Initialize(TestSessionMessageLogger.Instance, runtimeProviderInfo.RunSettings!);231 if (testRunCriteria.TestHostLauncher != null)232 {233 hostManager.SetCustomLauncher(testRunCriteria.TestHostLauncher);234 }235 var requestSender = new TestRequestSender(requestData.ProtocolConfig!, hostManager);236 if (testRunCriteria.TestSessionInfo != null)237 {238 // This function is used to either take a pre-existing proxy operation manager from239 // the test pool or to create a new proxy operation manager on the spot.240 Func<string, ProxyExecutionManager, ProxyOperationManager>241 proxyOperationManagerCreator = (242 string source,243 ProxyExecutionManager proxyExecutionManager) =>244 {245 var proxyOperationManager = TestSessionPool.Instance.TryTakeProxy(246 testRunCriteria.TestSessionInfo,247 source,248 runtimeProviderInfo.RunSettings,249 requestData);250 if (proxyOperationManager == null)251 {252 // If the proxy creation process based on test session info failed, then253 // we'll proceed with the normal creation process as if no test session254 // info was passed in in the first place.255 //256 // WARNING: This should not normally happen and it raises questions257 // regarding the test session pool operation and consistency.258 EqtTrace.Warning("ProxyExecutionManager creation with test session failed.");259 proxyOperationManager = new ProxyOperationManager(260 requestData,261 requestSender,262 hostManager,263 // There is always at least one, and all of them have the same framework and architecture.264 runtimeProviderInfo.SourceDetails[0].Framework,265 proxyExecutionManager);266 }267 return proxyOperationManager;268 };269 // In case we have an active test session, data collection needs were270 // already taken care of when first creating the session. As a consequence271 // we always return this proxy instead of choosing between the vanilla272 // execution proxy and the one with data collection enabled.273 return new ProxyExecutionManager(274 testRunCriteria.TestSessionInfo,275 proxyOperationManagerCreator,276 testRunCriteria.DebugEnabledForTestSession);277 }278 return isDataCollectorEnabled279 ? new ProxyExecutionManagerWithDataCollection(280 requestData,281 requestSender,282 hostManager,283 // There is always at least one, and all of them have the same framework and architecture.284 runtimeProviderInfo.SourceDetails[0].Framework!,285 new ProxyDataCollectionManager(286 requestData,287 runtimeProviderInfo.RunSettings,288 sources))289 : new ProxyExecutionManager(290 requestData,291 requestSender,292 hostManager,293 // There is always at least one, and all of them have the same framework and architecture.294 runtimeProviderInfo.SourceDetails[0].Framework!);295 }296 /// <inheritdoc/>297 public IProxyTestSessionManager? GetTestSessionManager(298 IRequestData requestData,299 StartTestSessionCriteria testSessionCriteria,300 IDictionary<string, SourceDetail> sourceToSourceDetailMap,301 IWarningLogger warningLogger)302 {303 var parallelLevel = VerifyParallelSettingAndCalculateParallelLevel(304 testSessionCriteria.Sources!.Count,305 testSessionCriteria.RunSettings!);306 bool isParallelRun = parallelLevel > 1;307 requestData.MetricsCollection.Add(308 TelemetryDataConstants.ParallelEnabledDuringStartTestSession,309 isParallelRun ? "True" : "False");310 var isDataCollectorEnabled = XmlRunSettingsUtilities.IsDataCollectionEnabled(testSessionCriteria.RunSettings);311 var isInProcDataCollectorEnabled = XmlRunSettingsUtilities.IsInProcDataCollectionEnabled(testSessionCriteria.RunSettings);312 List<TestRuntimeProviderInfo> testRuntimeProviders = GetTestRuntimeProvidersForUniqueConfigurations(testSessionCriteria.RunSettings!, sourceToSourceDetailMap, warningLogger, out var _);313 if (ShouldRunInProcess(314 testSessionCriteria.RunSettings!,315 isParallelRun,316 isDataCollectorEnabled || isInProcDataCollectorEnabled,317 testRuntimeProviders))318 {319 // In this case all tests will be run in the current process (vstest.console), so there is no320 // testhost to pre-start. No session will be created, and the session info will be null.321 return null;322 }323 Func<TestRuntimeProviderInfo, ProxyOperationManager?> proxyCreator = testRuntimeProviderInfo =>324 {325 var sources = testRuntimeProviderInfo.SourceDetails.Select(x => x.Source!).ToList();326 var hostManager = _testHostProviderManager.GetTestHostManagerByRunConfiguration(testRuntimeProviderInfo.RunSettings, sources);327 ThrowExceptionIfTestHostManagerIsNull(hostManager, testRuntimeProviderInfo.RunSettings);328 hostManager!.Initialize(TestSessionMessageLogger.Instance, testRuntimeProviderInfo.RunSettings!);329 if (testSessionCriteria.TestHostLauncher != null)330 {331 hostManager.SetCustomLauncher(testSessionCriteria.TestHostLauncher);332 }333 var requestSender = new TestRequestSender(requestData.ProtocolConfig!, hostManager)334 {335 CloseConnectionOnOperationComplete = false336 };337 // TODO (copoiena): For now we don't support data collection alongside test338 // sessions.339 //340 // The reason for this is that, in the case of Code Coverage for example, the341 // data collector needs to pass some environment variables to the testhost process342 // before the testhost process is started. This means that the data collector must343 // be running when the testhost process is spawned, however the testhost process344 // should be spawned during build, and it's problematic to have the data collector345 // running during build because it must instrument the .dll files that don't exist346 // yet.347 return isDataCollectorEnabled348 ? null349 // ? new ProxyOperationManagerWithDataCollection(350 // requestData,351 // requestSender,352 // hostManager,353 // new ProxyDataCollectionManager(354 // requestData,355 // runsettingsXml,356 // testSessionCriteria.Sources))357 // {358 // CloseRequestSenderChannelOnProxyClose = true359 // }360 : new ProxyOperationManager(361 requestData,362 requestSender,363 hostManager,364 // There is always at least one, and all of them have the same framework and architecture.365 testRuntimeProviderInfo.SourceDetails[0].Framework!);366 };367 // TODO: This condition should be returning the maxParallel level to avoid pre-starting way too many testhosts, because maxParallel level,368 // can be smaller than the number of sources to run.369 var maxTesthostCount = isParallelRun ? testSessionCriteria.Sources.Count : 1;370 return new ProxyTestSessionManager(testSessionCriteria, maxTesthostCount, proxyCreator, testRuntimeProviders);371 }372 private List<TestRuntimeProviderInfo> GetTestRuntimeProvidersForUniqueConfigurations(373 string runSettings,374 IDictionary<string, SourceDetail> sourceToSourceDetailMap,375 IWarningLogger warningLogger,376 out ITestRuntimeProvider? mostRecentlyCreatedInstance)377 {378 // Group source details to get unique frameworks and architectures for which we will run, so we can figure379 // out which runtime providers would run them, and if the runtime provider is shared or not.380 mostRecentlyCreatedInstance = null;381 var testRuntimeProviders = new List<TestRuntimeProviderInfo>();382 var uniqueRunConfigurations = sourceToSourceDetailMap.Values.GroupBy(k => $"{k.Framework}|{k.Architecture}");383 foreach (var runConfiguration in uniqueRunConfigurations)384 {385 // It is okay to take the first (or any) source detail in the group. We are grouping to get the same source detail, so all architectures and frameworks are the same.386 var sourceDetail = runConfiguration.First();387 var runsettingsXml = SourceDetailHelper.UpdateRunSettingsFromSourceDetail(runSettings, sourceDetail);388 var sources = runConfiguration.Select(c => c.Source!).ToList();389 var testRuntimeProvider = _testHostProviderManager.GetTestHostManagerByRunConfiguration(runsettingsXml, sources);390 if (testRuntimeProvider != null)391 {392 // Initialize here, because Shared is picked up from the instance, and it can be set during initalization.393 testRuntimeProvider.Initialize(TestSessionMessageLogger.Instance, runsettingsXml);394 // DO NOT move this above Initialize, the intialization can set Shared, to true, and we would not capture that.395 testRuntimeProviders.Add(new TestRuntimeProviderInfo(testRuntimeProvider.GetType(), testRuntimeProvider.Shared,396 runsettingsXml, sourceDetails: runConfiguration.ToList()));397 // Outputting the instance, because the code for in-process run uses it, and we don't want to resolve it one more time.398 mostRecentlyCreatedInstance = testRuntimeProvider;399 }400 else401 {402 testRuntimeProviders.Add(new TestRuntimeProviderInfo(type: null, shared: false, runsettingsXml, sourceDetails: runConfiguration.ToList()));403 }404 }405 WarnAboutNotFoundRuntimeProvidersOrThrowWhenNoneAreFound(testRuntimeProviders, warningLogger);406 // Do NOT return just found providers here, instead return all of them. Later sources will be split to criteria407 // and we need to have all the sources available there, and filter them down to skip the ones that don't408 // have runtime providers there.409 // var foundRuntimeProviders = testRuntimeProviders.Where(runtimeProvider => runtimeProvider.Type != null).ToList();410 return testRuntimeProviders;411 }412 /// <inheritdoc/>413 public ITestExtensionManager GetExtensionManager() => _testExtensionManager ??= new TestExtensionManager();414 /// <inheritdoc/>415 public ITestLoggerManager GetLoggerManager(IRequestData requestData)416 {417 return new TestLoggerManager(418 requestData,419 TestSessionMessageLogger.Instance,420 new InternalTestLoggerEvents(TestSessionMessageLogger.Instance));421 }422 #endregion423 private static int GetDistinctNumberOfSources(TestRunCriteria testRunCriteria)424 {425 // No point in creating more processes if number of sources is less than what the user426 // configured for.427 int numberOfSources = testRunCriteria.HasSpecificTests428 ? new HashSet<string>(429 testRunCriteria.Tests.Select(testCase => testCase.Source)).Count430 : testRunCriteria.Sources.Count();431 return numberOfSources;432 }433 /// <summary>434 /// Verifies parallel setting and returns parallel level to use based on the run criteria.435 /// </summary>436 ///437 /// <param name="sourceCount">The source count.</param>438 /// <param name="runSettings">The run settings.</param>439 ///440 /// <returns>The parallel level to use.</returns>441 private int VerifyParallelSettingAndCalculateParallelLevel(442 int sourceCount,443 string? runSettings)444 {445 // Default is 1.446 int parallelLevelToUse;447 try448 {449 // Check the user parallel setting.450 int maxCpuCount = RunSettingsUtilities.GetMaxCpuCount(runSettings);451 parallelLevelToUse = maxCpuCount == 0452 ? _environment.ProcessorCount453 : maxCpuCount;454 EqtTrace.Verbose(455 "TestEngine: Initializing Parallel Execution as MaxCpuCount is set to: {0}",456 parallelLevelToUse);457 var enableParallel = parallelLevelToUse > 1;458 // Verify if the number of sources is less than user setting of parallel.459 // We should use number of sources as the parallel level, if sources count is less460 // than parallel level.461 if (enableParallel)462 {463 // In case of a background discovery we want to reduce the number of cores utilized464 // to leave enough power for other tasks.465 var runSettingsEnvVariables = InferRunSettingsHelper.GetEnvironmentVariables(runSettings);466 string? isBackgroundDiscoveryEnabled = null;467 if (runSettingsEnvVariables is not null468 && runSettingsEnvVariables.TryGetValue("VSTEST_BACKGROUND_DISCOVERY", out isBackgroundDiscoveryEnabled)469 && isBackgroundDiscoveryEnabled == "1"470 && maxCpuCount == 0) // If user specifies a CPU count, respect it471 {472 // Dummy logic based on some observations, might need to be tweaked/improved.473 parallelLevelToUse = parallelLevelToUse switch474 {475 1 => 1,476 < 8 => (int)Math.Round(parallelLevelToUse / 2.0, MidpointRounding.AwayFromZero),477 _ => (int)Math.Round(0.75 * parallelLevelToUse, MidpointRounding.AwayFromZero),478 };479 }480 EqtTrace.Verbose("TestEngine.VerifyParallelSettingAndCalculateParallelLevel: Parallel execution is enabled (cpu count: {0}, max cpu count is {1}, calculated cpu count is {2}, background mode is {3}, number of sources is {4})", _environment.ProcessorCount, maxCpuCount, parallelLevelToUse, isBackgroundDiscoveryEnabled == "1" ? "enabled" : "disabled", sourceCount);481 parallelLevelToUse = Math.Min(sourceCount, parallelLevelToUse);482 // If only one source, no need to use parallel service client.483 enableParallel = parallelLevelToUse > 1;484 EqtTrace.Verbose(485 "TestEngine: ParallelExecution set to '{0}' as the parallel level is adjusted to '{1}' based on number of sources",486 enableParallel,487 parallelLevelToUse);488 }489 }490 catch (Exception ex)491 {492 EqtTrace.Error(493 "TestEngine: Error occurred while initializing ParallelExecution: {0}",494 ex);495 EqtTrace.Warning("TestEngine: Defaulting to Sequential Execution");496 parallelLevelToUse = 1;497 }498 return parallelLevelToUse;499 }500 private bool ShouldRunInProcess(501 string runsettings,502 bool isParallelEnabled,503 bool isDataCollectorEnabled,504 List<TestRuntimeProviderInfo> testHostProviders)505 {506 if (testHostProviders.Count > 1)507 {508 EqtTrace.Info("TestEngine.ShouldRunInNoIsolation: This run has multiple different architectures or frameworks, running in isolation (in a separate testhost proces).");509 return false;510 }511 var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);512 if (runConfiguration.InIsolation)513 {514 EqtTrace.Info("TestEngine.ShouldRunInNoIsolation: running test in isolation");515 return false;516 }517 // Run tests in isolation if run is authored using testsettings.518 if (InferRunSettingsHelper.IsTestSettingsEnabled(runsettings))519 {520 return false;521 }522 var currentProcessPath = _processHelper.GetCurrentProcessFileName();523 TPDebug.Assert(currentProcessPath != null, "currentProcessPath is null");524 // If running with the dotnet executable, then don't run in in process.525 if (currentProcessPath.EndsWith("dotnet", StringComparison.OrdinalIgnoreCase)526 || currentProcessPath.EndsWith("dotnet.exe", StringComparison.OrdinalIgnoreCase))527 {528 return false;529 }530 // Return true if531 // 1) Not running in parallel;532 // 2) Data collector is not enabled;533 // 3) Target platform is compatible or AnyCpu;534 // 4) DisableAppDomain is false;535 // 5) Not running in design mode;536 // 6) target framework is NETFramework (Desktop test);537 if (!isParallelEnabled &&538 !isDataCollectorEnabled &&539 (runConfiguration.TargetPlatform == ObjectModel.Constants.DefaultPlatform || runConfiguration.TargetPlatform == Architecture.AnyCPU) &&540 !runConfiguration.DisableAppDomain &&541 !runConfiguration.DesignMode &&542 runConfiguration.TargetFramework!.Name.IndexOf("netframework", StringComparison.OrdinalIgnoreCase) >= 0)543 {544 EqtTrace.Info("TestEngine.ShouldRunInNoIsolation: running test in process(inside vstest.console.exe process)");545 return true;546 }547 return false;548 }549 private static void ThrowExceptionIfTestHostManagerIsNull(ITestRuntimeProvider? testHostManager, string? settingsXml)550 {551 if (testHostManager == null)552 {553 EqtTrace.Error($"{nameof(TestEngine)}.{nameof(ThrowExceptionIfTestHostManagerIsNull)}: No suitable testHostProvider found for runsettings: {settingsXml}");554 throw new TestPlatformException(Resources.Resources.NoTestHostProviderFound);555 }556 }557 private static void WarnAboutNotFoundRuntimeProvidersOrThrowWhenNoneAreFound(List<TestRuntimeProviderInfo> testRuntimeProviders, IWarningLogger warningLogger)558 {559 if (!testRuntimeProviders.Any())560 throw new ArgumentException(null, nameof(testRuntimeProviders));561 // Throw when we did not find any runtime provider for any of the provided sources.562 var shouldThrow = testRuntimeProviders.All(runtimeProvider => runtimeProvider == null);563 var missingRuntimeProviders = testRuntimeProviders.Where(p => p.Type == null);564 if (missingRuntimeProviders.Any())565 {566 var stringBuilder = new StringBuilder();567 stringBuilder.AppendLine(Resources.Resources.NoTestHostProviderFound);568 foreach (var missingRuntimeProvider in missingRuntimeProviders)569 {570 var text = $"{nameof(TestEngine)}.{nameof(WarnAboutNotFoundRuntimeProvidersOrThrowWhenNoneAreFound)}: No suitable testHostProvider found for sources {string.Join(", ", missingRuntimeProvider.SourceDetails.Select(s => s.Source))} and runsettings: {missingRuntimeProvider.RunSettings}";571 if (shouldThrow)...

Full Screen

Full Screen

TestSessionPoolTests.cs

Source:TestSessionPoolTests.cs Github

copy

Full Screen

...20 var proxyTestSessionManager = new ProxyTestSessionManager(21 new StartTestSessionCriteria(),22 1,23 _ => null,24 new List<TestRuntimeProviderInfo>());25 Assert.IsNotNull(TestSessionPool.Instance);26 Assert.IsTrue(TestSessionPool.Instance.AddSession(testSessionInfo, proxyTestSessionManager));27 Assert.IsFalse(TestSessionPool.Instance.AddSession(testSessionInfo, proxyTestSessionManager));28 }29 [TestMethod]30 public void KillSessionShouldSucceedIfTestSessionExists()31 {32 TestSessionPool.Instance = null;33 var testSessionInfo = new TestSessionInfo();34 var mockProxyTestSessionManager = new Mock<ProxyTestSessionManager>(35 new StartTestSessionCriteria(),36 1,37 (Func<TestRuntimeProviderInfo, ProxyOperationManager>)(_ => null!),38 new List<TestRuntimeProviderInfo>());39 var mockRequestData = new Mock<IRequestData>();40 mockProxyTestSessionManager.SetupSequence(tsm => tsm.StopSession(It.IsAny<IRequestData>()))41 .Returns(true)42 .Returns(false);43 Assert.IsNotNull(TestSessionPool.Instance);44 Assert.IsFalse(TestSessionPool.Instance.KillSession(testSessionInfo, mockRequestData.Object));45 mockProxyTestSessionManager.Verify(tsm => tsm.StopSession(It.IsAny<IRequestData>()), Times.Never);46 Assert.IsTrue(TestSessionPool.Instance.AddSession(testSessionInfo, mockProxyTestSessionManager.Object));47 Assert.IsTrue(TestSessionPool.Instance.KillSession(testSessionInfo, mockRequestData.Object));48 mockProxyTestSessionManager.Verify(tsm => tsm.StopSession(mockRequestData.Object), Times.Once);49 Assert.IsTrue(TestSessionPool.Instance.AddSession(testSessionInfo, mockProxyTestSessionManager.Object));50 Assert.IsFalse(TestSessionPool.Instance.KillSession(testSessionInfo, mockRequestData.Object));51 mockProxyTestSessionManager.Verify(tsm => tsm.StopSession(mockRequestData.Object), Times.Exactly(2));52 }53 [TestMethod]54 public void TakeProxyShouldSucceedIfMatchingCriteriaAreCorrect()55 {56 TestSessionPool.Instance = null;57 var testSessionInfo = new TestSessionInfo();58 var mockRequestData = new Mock<IRequestData>();59 var mockProxyTestSessionManager = new Mock<ProxyTestSessionManager>(60 new StartTestSessionCriteria(),61 1,62 (Func<TestRuntimeProviderInfo, ProxyOperationManager>)(_ => null!),63 new List<TestRuntimeProviderInfo>());64 mockProxyTestSessionManager.SetupSequence(tsm => tsm.DequeueProxy(It.IsAny<string>(), It.IsAny<string>()))65 .Throws(new InvalidOperationException("Test Exception"))66 .Returns(new ProxyOperationManager(null, null!, null!, Framework.DefaultFramework));67 Assert.IsNotNull(TestSessionPool.Instance);68 // Take proxy fails because test session is invalid.69 Assert.IsNull(TestSessionPool.Instance.TryTakeProxy(new TestSessionInfo(), string.Empty, string.Empty, mockRequestData.Object));70 mockProxyTestSessionManager.Verify(tsm => tsm.DequeueProxy(It.IsAny<string>(), It.IsAny<string>()), Times.Never);71 Assert.IsTrue(TestSessionPool.Instance.AddSession(testSessionInfo, mockProxyTestSessionManager.Object));72 // First TakeProxy fails because of throwing, see setup sequence.73 Assert.IsNull(TestSessionPool.Instance.TryTakeProxy(testSessionInfo, string.Empty, string.Empty, mockRequestData.Object));74 mockProxyTestSessionManager.Verify(tsm => tsm.DequeueProxy(It.IsAny<string>(), It.IsAny<string>()), Times.Once);75 // Second TakeProxy succeeds, see setup sequence.76 Assert.IsNotNull(TestSessionPool.Instance.TryTakeProxy(testSessionInfo, string.Empty, string.Empty, mockRequestData.Object));77 mockProxyTestSessionManager.Verify(tsm => tsm.DequeueProxy(It.IsAny<string>(), It.IsAny<string>()), Times.Exactly(2));78 }79 [TestMethod]80 public void ReturnProxyShouldSucceedIfProxyIdIsValid()81 {82 TestSessionPool.Instance = null;83 var testSessionInfo = new TestSessionInfo();84 var mockProxyTestSessionManager = new Mock<ProxyTestSessionManager>(85 new StartTestSessionCriteria(),86 1,87 (Func<TestRuntimeProviderInfo, ProxyOperationManager>)(_ => null!),88 new List<TestRuntimeProviderInfo>());89 mockProxyTestSessionManager.SetupSequence(tsm => tsm.EnqueueProxy(It.IsAny<int>()))90 .Throws(new ArgumentException("Test Exception"))91 .Throws(new InvalidOperationException("Test Exception"))92 .Returns(true);93 Assert.IsNotNull(TestSessionPool.Instance);94 Assert.IsFalse(TestSessionPool.Instance.ReturnProxy(new TestSessionInfo(), 0));95 mockProxyTestSessionManager.Verify(tsm => tsm.EnqueueProxy(It.IsAny<int>()), Times.Never);96 Assert.IsTrue(TestSessionPool.Instance.AddSession(testSessionInfo, mockProxyTestSessionManager.Object));97 // Simulates proxy id not found (see setup sequence).98 Assert.ThrowsException<ArgumentException>(() => TestSessionPool.Instance.ReturnProxy(testSessionInfo, 0));99 mockProxyTestSessionManager.Verify(tsm => tsm.EnqueueProxy(It.IsAny<int>()), Times.Once);100 // Simulates proxy already available (see setup sequence).101 Assert.IsFalse(TestSessionPool.Instance.ReturnProxy(testSessionInfo, 0));102 mockProxyTestSessionManager.Verify(tsm => tsm.EnqueueProxy(It.IsAny<int>()), Times.Exactly(2));...

Full Screen

Full Screen

TestRuntimeProviderInfo.cs

Source:TestRuntimeProviderInfo.cs Github

copy

Full Screen

...3using System;4using System.Collections.Generic;5using Microsoft.VisualStudio.TestPlatform.ObjectModel;6namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7public class TestRuntimeProviderInfo8{9 public Type? Type { get; }10 public bool Shared { get; }11 public string? RunSettings { get; }12 public List<SourceDetail> SourceDetails { get; }13 public TestRuntimeProviderInfo(Type? type, bool shared, string? runSettings, List<SourceDetail> sourceDetails)14 {15 Type = type;16 Shared = shared;17 RunSettings = runSettings;18 SourceDetails = sourceDetails;19 }20}...

Full Screen

Full Screen

TestRuntimeProviderInfo

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9{10 {11 static void Main(string[] args)12 {13 TestRuntimeProviderInfo testRuntimeProviderInfo = new TestRuntimeProviderInfo();14 TestPlatformOptions testPlatformOptions = new TestPlatformOptions();15 testPlatformOptions.MaxCpuCount = 1;16 testPlatformOptions.SynchronousEvents = true;17 testPlatformOptions.ResetCaches = true;18 testPlatformOptions.CacheDirectory = @"C:\Users\Public\Documents\Visual Studio 2015\testResults";19 testRuntimeProviderInfo.Initialize(testPlatformOptions);20 testRuntimeProviderInfo.TestRuntimeProvider = "testRuntimeProvider";21 Console.WriteLine(testRuntimeProviderInfo.TestRuntimeProvider);22 Console.ReadLine();23 }24 }25}26using System;27using System.Collections.Generic;28using System.Linq;29using System.Text;30using System.Threading.Tasks;31using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;32using Microsoft.VisualStudio.TestPlatform.ObjectModel;33using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;34{35 {36 static void Main(string[] args)37 {38 TestRuntimeProviderInfo testRuntimeProviderInfo = new TestRuntimeProviderInfo();39 TestPlatformOptions testPlatformOptions = new TestPlatformOptions();40 testPlatformOptions.MaxCpuCount = 1;41 testPlatformOptions.SynchronousEvents = true;42 testPlatformOptions.ResetCaches = true;43 testPlatformOptions.CacheDirectory = @"C:\Users\Public\Documents\Visual Studio 2015\testResults";44 testRuntimeProviderInfo.Initialize(testPlatformOptions);45 testRuntimeProviderInfo.TestRuntimeProvider = "testRuntimeProvider";46 Console.WriteLine(testRuntimeProviderInfo.TestRuntimeProvider);47 Console.ReadLine();48 }49 }50}51using System;52using System.Collections.Generic;53using System.Linq;54using System.Text;55using System.Threading.Tasks;56using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;

Full Screen

Full Screen

TestRuntimeProviderInfo

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2{3 {4 static void Main(string[] args)5 {6 TestRuntimeProviderInfo testRuntimeProviderInfo = new TestRuntimeProviderInfo("testRuntimeProviderInfo");7 testRuntimeProviderInfo.TestRuntimeProviderPath = "testRuntimeProviderPath";8 testRuntimeProviderInfo.TestRuntimeProviderExtensionPath = "testRuntimeProviderExtensionPath";9 testRuntimeProviderInfo.TestRuntimeProviderVersion = "testRuntimeProviderVersion";10 testRuntimeProviderInfo.IsDefault = true;11 Console.WriteLine(testRuntimeProviderInfo.TestRuntimeProviderPath);12 Console.WriteLine(testRuntimeProviderInfo.TestRuntimeProviderExtensionPath);13 Console.WriteLine(testRuntimeProviderInfo.TestRuntimeProviderVersion);14 Console.WriteLine(testRuntimeProviderInfo.IsDefault);15 }16 }17}18using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;19{20 {21 static void Main(string[] args)22 {23 TestRuntimeProviderManager testRuntimeProviderManager = new TestRuntimeProviderManager();24 testRuntimeProviderManager.LoadTestRuntimeProviders();25 testRuntimeProviderManager.GetTestRuntimeProvider("testRuntimeProvider");26 }27 }28}29using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;30using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;31using Microsoft.VisualStudio.TestPlatform.ObjectModel;32using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;33using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;34using System.Collections.Generic;35{36 {37 static void Main(string[] args)38 {39 TestRuntimeProvider testRuntimeProvider = new TestRuntimeProvider("testRuntimeProvider", "testRuntimeProviderPath", "testRuntimeProviderExtensionPath", "testRuntimeProviderVersion", true);40 testRuntimeProvider.GetTestHostProcessStartInfo(new TestProcessStartInfo(), new TestRunCriteria(new List<string>(), 1));41 testRuntimeProvider.GetTestHostProcessStartInfo(new TestProcessStartInfo(), new TestRunCriteria(new List<string>(), 1), new DataCollectionParameters(new

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in TestRuntimeProviderInfo

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful