Example #1
0
        internal static Task StartAsync
        (
            ILoadTestExecution loadTestExecution,
            IReadOnlyList <ISchedule> schedules,
            IHttpStatusResultService httpStatusResultService,
            CancellationToken cancellationToken,
            ClientOptions options
        )
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseStartup <Startup>()
                       .UseUrls("http://localhost:5000")
                       .ConfigureServices(services =>
            {
                ConfigureServices(services, httpStatusResultService, options.DatabaseFile);

                services.AddSingleton <ICancelTokenReference>(new CancelTokenReference(cancellationToken));

                services.AddSingleton(loadTestExecution);
                services.AddSingleton(schedules);
                services.AddSingleton(options);
            })
                       .Build();

            var stopWebUi = new CancellationTokenSource();

            cancellationToken.Register(Cancel(stopWebUi));

            return(host.RunAsync(stopWebUi.Token));
        }
Example #2
0
        public static void Run(ILoadTestExecution testExecution, IReadOnlyList <ISchedule> schedule, IHttpStatusResultService httpStatusResultService, string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddCommandLine(args)
                         .Build();

            var clientOptions = new ClientOptions(config.GetValue <string>("databaseFile"));

            Run(testExecution, schedule, httpStatusResultService, clientOptions);
        }
Example #3
0
        private static void InitializeWithServices(ILoadTestExecution loadTestExecution, IServiceCollection services)
        {
            var sp = services.BuildServiceProvider();
            var iterationResultRepository = sp.GetService <IIterationResultRepository>();

            if (loadTestExecution != null)
            {
                loadTestExecution.UserIterationFinished += LogIteration(iterationResultRepository);
            }

            DbInitializer.Initialize(sp.GetService <IDbConnection>());
        }
 public ExecuteTestsService
 (
     ClientOptions clientOptions,
     ILoadTestExecution loadTestExecution,
     IReadOnlyList <ISchedule> schedules,
     ISaveIterationQueue saveIterationQueue,
     ICancelTokenReference cancelTokenReference
 )
 {
     _clientOptions        = clientOptions;
     _loadTestExecution    = loadTestExecution;
     _schedules            = schedules;
     _saveIterationQueue   = saveIterationQueue;
     _cancelTokenReference = cancelTokenReference;
 }
Example #5
0
        public static void Run(ILoadTestExecution testExecution, IReadOnlyList <ISchedule> schedule, IHttpStatusResultService httpStatusResultService, ClientOptions clientOptions)
        {
            var cancellationSource = new CancellationTokenSource();

            Console.CancelKeyPress += ((sender, cancelEventArgs) =>
            {
                cancellationSource.Cancel();
                cancelEventArgs.Cancel = true;
            });

            //var t = new Timer(_ => { cancellationSource.Cancel(); }, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(0));

            var webUi = Program.StartAsync(testExecution, schedule, httpStatusResultService, cancellationSource.Token, clientOptions);

            Task.WaitAll(webUi);
        }
Example #6
0
        public static void Run(ILoadTestExecution testExecution, IReadOnlyList <ISchedule> schedule, IHttpStatusResultService httpStatusResultService)
        {
            var cancellationSource = new CancellationTokenSource();

            Console.CancelKeyPress += ((sender, args) =>
            {
                cancellationSource.Cancel();
                args.Cancel = true;
            });

            var options = new ParallelOptions
            {
                CancellationToken = cancellationSource.Token
            };

            Parallel.Invoke
            (
                options,
                () => testExecution.Execute(schedule, cancellationSource.Token),
                () => Program.Start(testExecution, httpStatusResultService, cancellationSource.Token)
            );
        }
Example #7
0
        internal static void Start(ILoadTestExecution loadTestExecution, IHttpStatusResultService httpStatusResultService, CancellationToken?cancellationToken = null)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseStartup <Startup>()
                       .UseUrls("http://localhost:5000")
                       .ConfigureServices(services =>
            {
                ConfigureServices(services, httpStatusResultService);

                InitializeWithServices(loadTestExecution, services);
            })
                       .Build();

            if (cancellationToken.HasValue)
            {
                host.Run(cancellationToken.Value);
            }
            else
            {
                host.Run();
            }
        }