public static void Main(string[] args) { ProcessEnvironmentVariables(); ProcessCommandArgs(args); ValidateParameters(); Smoker = new Smoker.Test(Config.FileList, Config.Host); // run one test iteration if (!Config.RunLoop && !Config.RunWeb) { if (!Smoker.Run().Result) { Environment.Exit(-1); } return; } IWebHost host = null; // configure web server if (Config.RunWeb) { // use the default web host builder + startup IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseStartup <Startup>() .UseUrls("http://*:4122/"); // build the host host = builder.Build(); } using (CancellationTokenSource ctCancel = new CancellationTokenSource()) { // setup ctl c handler Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; ctCancel.Cancel(); Console.WriteLine("Ctl-C Pressed - Starting shutdown ..."); // give threads a chance to shutdown Thread.Sleep(500); // end the app Environment.Exit(0); }; // run tests in config.RunLoop if (Config.RunLoop) { TaskRunner tr; for (int i = 0; i < Config.Threads; i++) { tr = new TaskRunner { TokenSource = ctCancel }; tr.Task = Smoker.RunLoop(i, App.Config, tr.TokenSource.Token); TaskRunners.Add(tr); } } // run the web server if (Config.RunWeb) { try { Console.WriteLine($"Version: {Helium.Version.AssemblyVersion}"); host.Run(); Console.WriteLine("Web server shutdown"); } catch (Exception ex) { Console.WriteLine($"Web Server Exception\n{ex}"); } return; } // run the task loop if (Config.RunLoop && TaskRunners.Count > 0) { // Wait for all tasks to complete List <Task> tasks = new List <Task>(); foreach (var trun in TaskRunners) { tasks.Add(trun.Task); } // wait for ctrl c Task.WaitAll(tasks.ToArray()); } } }
// main entry point public static async Task Main(string[] args) { int sleepMs = 0; string baseUrl = "http://localhost:4120"; string defaultInputFile = "integration-test.json"; bool loop = false; List <string> fileList = new List <string>(); // process the command line args if (args.Length > 0) { if (args[0] == "--help") { // display usage Usage(); return; } int i = 0; while (i < args.Length) { // process all of the args in pairs if (i < args.Length - 1) { // handle host (-h http://localhost:4120/) if (args[i] == "-h") { baseUrl = args[i + 1].Trim(); // make it easier to pass host if (!baseUrl.ToLower().StartsWith("http")) { if (baseUrl.ToLower().StartsWith("localhost")) { baseUrl = "http://" + baseUrl; } else { baseUrl = string.Format("https://{0}.azurewebsites.net", baseUrl); } } i++; } // handle input files (-i inputFile.json input2.json input3.json) else if (i < args.Length - 1 && (args[i] == "-i")) { while (i + 1 < args.Length && !args[i + 1].StartsWith("-")) { string file = args[i + 1].Trim(); if (!System.IO.File.Exists(file)) { Console.WriteLine("File not found: {0}", file); Environment.Exit(-1); } fileList.Add(file); i++; } } // handle sleep (-s sleepMS) else if (args[i] == "-s") { if (int.TryParse(args[i + 1], out sleepMs) && sleepMs > 0) { // set loop to true loop = true; i++; } else { // exit on error Console.WriteLine("Invalid sleep (millisecond) paramter: {0}\r\n", args[i + 1]); Usage(); return; } } i++; } } } if (fileList.Count == 0) { fileList.Add(defaultInputFile); } Smoker.Test smoker = new Smoker.Test(fileList, baseUrl); if (!loop) { if (!smoker.Run().Result) { Environment.Exit(-1); } return; } await smoker.RunLoop(sleepMs); }
public static void Main(string[] args) { ProcessEnvironmentVariables(); ProcessCommandArgs(args); ValidateParameters(); smoker = new Smoker.Test(config.FileList, config.Host); // run one test iteration if (!config.RunLoop && !config.RunWeb) { if (!smoker.Run().Result) { Environment.Exit(-1); } return; } Task webTask = null; // run as a web server if (config.RunWeb) { // use the default web host builder + startup IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseStartup <Startup>() .UseUrls("http://*:4122/"); // build the host IWebHost host = builder.Build(); // run the web server webTask = host.RunAsync(); } // run tests in config.RunLoop if (config.RunLoop) { TaskRunner tr; for (int i = 0; i < config.Threads; i++) { tr = new TaskRunner(); tr.TokenSource = new CancellationTokenSource(); tr.Task = smoker.RunLoop(i, App.config, tr.TokenSource.Token); taskRunners.Add(tr); } } if (config.RunWeb) { // wait for web server to complete or ctrl c webTask.Wait(); } else if (config.RunLoop && taskRunners.Count > 0) { // Wait for all tasks to complete List <Task> tasks = new List <Task>(); foreach (var trun in taskRunners) { tasks.Add(trun.Task); } // wait for the run loop to complete or ctrl c Task.WaitAll(tasks.ToArray()); } }