public void Production_DotNet_Startup(string sampleName) { var framework = "CoreCLR"; var applicationFramework = Runtimes.GetFrameworkName(framework); var testName = $"{sampleName}.{framework}.{nameof(Production_DotNet_Startup)}"; var logger = LogUtility.LoggerFactory.CreateLogger(testName); var testProject = _sampleManager.GetDotNetPublishedSample(sampleName, applicationFramework); Assert.True(testProject != null, $"Fail to set up test project."); logger.LogInformation($"Test project is set up at {testProject}"); var startInfo = GetStartInfo(testProject, sampleName); RunStartup(5000, logger, startInfo); }
public void GracefulExit(string sampleName) { var framework = "CoreCLR"; var appliationFramework = Runtimes.GetFrameworkName(framework); var testName = $"{sampleName}.{framework}.{nameof(GracefulExit)}"; var logger = LogUtility.LoggerFactory.CreateLogger(testName); var testProject = _sampleManager.GetDotNetPublishedSample(sampleName, appliationFramework); Assert.True(testProject != null, $"Fail to set up test project."); logger.LogInformation($"Test project is set up at {testProject}"); var startInfo = GetStartInfo(testProject, sampleName); var process = Process.Start(startInfo); HttpResponseMessage response = null; try { Task <HttpResponseMessage> webtask = null; var url = "http://localhost:5000/"; var responseRetrived = false; using (var client = new HttpClient()) { for (var i = 0; i < _retry; ++i) { try { webtask = client.GetAsync(url); if (webtask.Wait(_timeout)) { responseRetrived = true; break; } else { logger.LogError("Http client timeout."); break; } } catch (Exception) { continue; } } } if (responseRetrived) { response = webtask.Result; response.EnsureSuccessStatusCode(); } } finally { if (process != null && !process.HasExited) { process.KillTree(); } if (response != null) { response.Dispose(); } } }
public async Task <StressTestServerStartResult> StartAsync() { var framework = "CoreCLR"; var fullTestName = $"{_testMethodName}.{_testName}.{framework}"; fullTestName = fullTestName.Replace('_', '.'); var loggerFactory = LogUtility.LoggerFactory; _logger = loggerFactory.CreateLogger(fullTestName); var baseAddress = $"http://localhost:{_port}/"; var p = new DeploymentParameters( PathHelper.GetTestAppFolder(_testName), _serverType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { SiteName = _testName, ApplicationBaseUriHint = baseAddress, TargetFramework = Runtimes.GetFrameworkName(framework), }; var deployerLoggerFactory = StressConfig.Instance.DeployerLogging ? loggerFactory : NullLoggerFactory.Instance; _applicationDeployer = ApplicationDeployerFactory.Create(p, deployerLoggerFactory); var deploymentResult = _applicationDeployer.DeployAsync().Result; baseAddress = deploymentResult.ApplicationBaseUri; _logger.LogInformation($"Test project is set up at {deploymentResult.ContentRoot}"); var result = new StressTestServerStartResult { ServerHandle = this }; var serverVerificationClient = new HttpClient { BaseAddress = new Uri(baseAddress) }; HttpResponseMessage response = null; for (var i = 0; i < 20; ++i) { try { _logger.LogInformation($"Pinging {serverVerificationClient.BaseAddress} to ensure server booted properly"); response = await serverVerificationClient.GetAsync(serverVerificationClient.BaseAddress); break; } catch (TimeoutException) { _logger.LogError("Http client timeout."); break; } catch (Exception) { _logger.LogInformation("Failed to ping server. Retrying..."); Thread.Sleep(TimeSpan.FromSeconds(1)); continue; } } result.SuccessfullyStarted = false; if (response != null) { _logger.LogInformation($"Response {response.StatusCode}"); if (response.IsSuccessStatusCode) { _logger.LogInformation("Server started successfully"); result.SuccessfullyStarted = true; ClientFactory = () => new RequestTrackingHttpClient(baseAddress, _metricCollector); } } return(result); }