Ejemplo n.º 1
0
        public void SelfhostWeb_Designtime(string sampleName, string framework, string command, int port)
        {
            var logger = _loggerFactory.CreateLogger(this.GetType(), sampleName, command, nameof(SelfhostWeb_Designtime), framework);

            using (logger.BeginScope("Root"))
            {
                var samplePath = PathHelper.GetTestAppFolder(sampleName);

                Assert.NotNull(samplePath);

                var restoreResult = DnuHelper.RestorePackage(samplePath, framework, quiet: true);
                Assert.True(restoreResult, "Failed to restore packages");

                var prepare = EnvironmentHelper.Prepare();
                Assert.True(prepare, "Failed to prepare the environment");

                var testAppStartInfo = DnxHelper.BuildStartInfo(samplePath, framework: framework, command: command);
                var runner           = new WebApplicationFirstRequest(
                    new StartupRunnerOptions {
                    ProcessStartInfo = testAppStartInfo, Logger = logger, IterationCount = _iterationCount
                },
                    port: port, path: "/", timeout: TimeSpan.FromSeconds(60));

                var errors = new List <string>();
                var result = runner.Run();

                Assert.True(result, "Fail:\t" + string.Join("\n\t", errors));
            }
        }
Ejemplo n.º 2
0
        public void Console_DesignTime(string sampleName, string framework)
        {
            var logger = _loggerFactory.CreateLogger(GetType(), "run", sampleName, nameof(Console_DesignTime), framework);

            using (logger.BeginScope("Root"))
            {
                var samplePath = PathHelper.GetTestAppFolder(sampleName);

                logger.LogInformation("Probe application under " + samplePath);
                Assert.NotNull(samplePath);

                var restoreResult = DnuHelper.RestorePackage(samplePath, framework, quiet: true);
                Assert.True(restoreResult, "Failed to restore packages");

                var prepare = EnvironmentHelper.Prepare();
                Assert.True(prepare, "Failed to prepare the environment");

                var options = new StartupRunnerOptions
                {
                    ProcessStartInfo = DnxHelper.BuildStartInfo(samplePath, framework: framework),
                    Logger           = logger,
                    IterationCount   = _iterationCount
                };
                var runner = new ConsoleAppStartup(options);

                var errors = new List <string>();
                var result = runner.Run();

                Assert.True(result, "Fail:\t" + string.Join("\n\t", errors));
            }
        }
Ejemplo n.º 3
0
        public void Development_Update_Startup(string sampleName)
        {
            var framework = PlatformServices.Default.Runtime.RuntimeType;
            var testName  = $"{sampleName}.{framework}.{nameof(Development_Startup)}";
            var logger    = LogUtility.LoggerFactory.CreateLogger(testName);

            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, $"Fail to set up test project.");
            logger.LogInformation($"Test project is set up at {testProject}");

            var testAppStartInfo = DnxHelper.GetDefaultInstance().BuildStartInfo(testProject, framework, "run");

            var process = Process.Start(testAppStartInfo);

            Thread.Sleep(1000);
            process.Kill();
            logger.LogInformation("Run server before updating");

            // update source code
            var lines = File.ReadLines(Path.Combine(testProject, "Startup.cs")).ToArray();

            for (var i = 0; i < lines.Length; ++i)
            {
                if (lines[i].Trim().StartsWith("private const string FixedResponse = "))
                {
                    lines[i] = $"private const string FixedResponse = \"{Guid.NewGuid()}\";";
                }
            }

            var retry = 0;

            while (retry < 3)
            {
                try
                {
                    File.WriteAllLines(Path.Combine(testProject, "Startup.cs"), lines);
                    break;
                }
                catch (IOException)
                {
                    ++retry;
                }
            }
            Assert.True(retry <= 3, "Failed to write the source code for 3 times.");
            logger.LogInformation("Update source code");

            RunStartup(5000, logger, testAppStartInfo);
        }
Ejemplo n.º 4
0
        public void Development_Startup(string sampleName)
        {
            var framework = PlatformServices.Default.Runtime.RuntimeType;
            var testName  = $"{sampleName}.{framework}.{nameof(Development_Startup)}";
            var logger    = LogUtility.LoggerFactory.CreateLogger(testName);

            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, $"Fail to set up test project.");
            logger.LogInformation($"Test project is set up at {testProject}");

            var testAppStartInfo = DnxHelper.GetDefaultInstance().BuildStartInfo(testProject, framework, "run");

            RunStartup(5000, logger, testAppStartInfo);
        }
Ejemplo n.º 5
0
        public void Production_Startup(string sampleName)
        {
            var framework           = PlatformServices.Default.Runtime.RuntimeType;
            var appliationFramework = GetFrameworkName(framework);
            var testName            = $"{sampleName}.{framework}.{nameof(Production_Startup)}";
            var logger = LogUtility.LoggerFactory.CreateLogger(testName);

            var testProject = _sampleManager.GetDnxPublishedSample(sampleName, appliationFramework);

            Assert.True(testProject != null, $"Fail to set up test project.");
            logger.LogInformation($"Test project is set up at {testProject}");

            // --project "%~dp0packages\BasicKestrel\1.0.0\root"
            var root             = Path.Combine(testProject, "approot", "packages", sampleName, "1.0.0", "root");
            var testAppStartInfo = DnxHelper.GetDefaultInstance().BuildStartInfo(testProject, framework, $"--project {root} run");

            RunStartup(5000, logger, testAppStartInfo);
        }
Ejemplo n.º 6
0
        public void DnuPublishNoSource(string sampleName)
        {
            var framework   = PlatformServices.Default.Runtime.RuntimeType;
            var testName    = $"{sampleName}.{framework}.{nameof(DnuPublishNoSource)}";
            var testProject = _sampleManager.GetRestoredSample(sampleName);

            Assert.True(testProject != null, $"Fail to set up test project.");

            var testOutput = Path.Combine(PathHelper.GetNewTempFolder(), testName);

            Directory.CreateDirectory(testOutput);

            using (Collector.StartCollection())
            {
                DnxHelper.GetDefaultInstance().Publish(
                    workingDir: testProject,
                    outputDir: testOutput,
                    framework: framework,
                    nosource: true,
                    quiet: true);
            }
        }
Ejemplo n.º 7
0
        public void PublishAndRun(string sampleName, string framework)
        {
            DnxHelper.GetDefaultInstance().GetDnxExecutable(framework);

            _log = _loggerFactory.CreateLogger($"{nameof(AntaresStartup)}.{nameof(PublishAndRun)}.{sampleName}.{framework}");
            DeployTestSite(sampleName, framework);

            var client = new HttpClient();
            var url    = $"http://{_testsitename}.azurewebsites.net";

            var sw = new Stopwatch();

            sw.Start();

            var webstask = client.GetAsync(url);

            if (webstask.Wait(TimeSpan.FromMinutes(10)))
            {
                sw.Stop();

                _log.LogInformation($"Latency: {sw.ElapsedMilliseconds}");
                _log.LogInformation($"Response: {webstask.Result.StatusCode}");

                if (webstask.Result.IsSuccessStatusCode)
                {
                    _summary.Aggregate(new BenchmarkIterationSummary {
                        TimeElapsed = (long)sw.ElapsedMilliseconds
                    });
                }
            }
            else
            {
                _log.LogError("Http client timeout after 10 minute.");
            }

            SaveSummary(_log);
        }
Ejemplo n.º 8
0
        private void DeployTestSite(string sampleName, string framework)
        {
            var runner = new CommandLineRunner()
            {
                Timeout = TimeSpan.FromMinutes(5)
            };

            _testsitesource = Path.GetTempFileName();
            File.Delete(_testsitesource);
            Directory.CreateDirectory(_testsitesource);

            var sourcePath = PathHelper.GetTestAppFolder(sampleName);

            Assert.NotNull(sourcePath);

            runner.Execute($"git clean -xdff .", sourcePath);
            Assert.NotEqual(-1, runner.Execute($"robocopy {sourcePath} {_testsitesource} /E /S /XD node_modules")); // robcopy doesn't return 0
            File.WriteAllText(Path.Combine(_testsitesource, "global.json"), DnxHelper.GetDefaultInstance().BuildGlobalJson(framework));
            File.Copy(PathHelper.GetNuGetConfig(), Path.Combine(_testsitesource, "NuGet.config"));

            _log.LogInformation($"Testsite sources are copied to {_testsitesource}.");

            CreateTestSite();

            Assert.Equal(0, runner.Execute("git add -A .", _testsitesource));
            Assert.Equal(0, runner.Execute("git commit -m \"init\"", _testsitesource));

            var giturl = $"https://{_username}:{_password}@{_testsitename}.scm.azurewebsites.net:443/{_testsitename}.git";

            Assert.Equal(0, runner.Execute($"git remote set-url azure {giturl}", _testsitesource));

            _log.LogInformation("Git repository is set up at testsite source folder");

            runner.Timeout = TimeSpan.FromMinutes(15);
            Assert.Equal(0, runner.Execute($"git push azure master", _testsitesource));
        }