public static HttpPipelineTransport Create(PerfStressOptions options) { HttpClient httpClient; if (options.Insecure) { httpClient = new HttpClient(new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true }); } else { httpClient = new HttpClient(); } var httpClientTransport = new HttpClientTransport(httpClient); if (!string.IsNullOrEmpty(options.Host)) { return(new ChangeUriTransport(httpClientTransport, options.Host, options.Port)); } else { return(httpClientTransport); } }
private static async Task Run(Type testType, PerfStressOptions options) { if (!GCSettings.IsServerGC) { throw new InvalidOperationException("Requires server GC"); } Console.WriteLine("=== Options ==="); Console.WriteLine(JsonSerializer.Serialize(options, options.GetType(), new JsonSerializerOptions() { WriteIndented = true })); Console.WriteLine(); using var setupStatusCts = new CancellationTokenSource(); var setupStatusTask = PrintStatusAsync("=== Setup ===", () => ".", newLine: false, setupStatusCts.Token); using var cleanupStatusCts = new CancellationTokenSource(); Task cleanupStatusTask = null; var tests = new IPerfStressTest[options.Parallel]; for (var i = 0; i < options.Parallel; i++) { tests[i] = (IPerfStressTest)Activator.CreateInstance(testType, options); } try { await tests[0].GlobalSetupAsync(); try { await Task.WhenAll(tests.Select(t => t.SetupAsync())); setupStatusCts.Cancel(); await setupStatusTask; if (options.Warmup > 0) { await RunTestsAsync(tests, options.Sync, options.Parallel, options.Warmup, "Warmup"); } for (var i = 0; i < options.Iterations; i++) { var title = "Test"; if (options.Iterations > 1) { title += " " + (i + 1); } await RunTestsAsync(tests, options.Sync, options.Parallel, options.Duration, title); } } finally { if (!options.NoCleanup) { if (cleanupStatusTask == null) { cleanupStatusTask = PrintStatusAsync("=== Cleanup ===", () => ".", newLine: false, cleanupStatusCts.Token); } await Task.WhenAll(tests.Select(t => t.CleanupAsync())); } } } finally { if (!options.NoCleanup) { if (cleanupStatusTask == null) { cleanupStatusTask = PrintStatusAsync("=== Cleanup ===", () => ".", newLine: false, cleanupStatusCts.Token); } await tests[0].GlobalCleanupAsync(); } } cleanupStatusCts.Cancel(); if (cleanupStatusTask != null) { await cleanupStatusTask; } }