public WebTestsFixture()
    {
        var logger = new LoggerFactory()
                     .AddConsole(LogLevel.Information)
                     .CreateLogger("Regression");

        _loggerScope = logger.BeginScope("RegressionTestSuite");
        var deploymentParameters = new DeploymentParameters(
            TestConfiguration.Configuration.Get <string>("Settings:ApplicationPath"),
            (ServerType)Enum.Parse(typeof(ServerType), TestConfiguration.Configuration.Get <string>("Settings:ServerType")),
            RuntimeFlavor.Clr,
            RuntimeArchitecture.x86)
        {
            ApplicationBaseUriHint = TestConfiguration.Configuration.Get <string>("Settings:ApplicationUri"),
            EnvironmentName        = TestConfiguration.Configuration.Get <string>("Settings:EnvironmentName"),
            PublishWithNoSource    = false
        };

        _deployer        = ApplicationDeployerFactory.Create(deploymentParameters, logger);
        DeploymentResult = _deployer.Deploy();
    }
Beispiel #2
0
        public async Task <StressTestServerStartResult> StartAsync()
        {
            var framework    = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType;
            var fullTestName = $"{_testMethodName}.{_testName}.{framework}";

            fullTestName = fullTestName.Replace('_', '.');

            _logger = LogUtility.LoggerFactory.CreateLogger(fullTestName);

            var baseAddress = $"http://localhost:{_port}/";

            var p = new DeploymentParameters(PathHelper.GetTestAppFolder(_testName), _serverType, RuntimeFlavor.Clr, RuntimeArchitecture.x64)
            {
                SiteName = _testName,
                ApplicationBaseUriHint = baseAddress,
                TargetFramework        = "net451"
            };

            ILogger deployerLogger;

            if (StressConfig.Instance.DeployerLogging)
            {
                deployerLogger = _logger;
            }
            else
            {
                deployerLogger = new NullLogger();
            }

            _applicationDeployer = ApplicationDeployerFactory.Create(p, deployerLogger);
            var deploymentResult = _applicationDeployer.Deploy();

            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 (int 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);
        }