Esempio n. 1
0
        public async Task HttpClient_DefaultConfigThroughputTests(string endpoint, int rate, int within = 10)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddCountersTracing();
            serviceCollection.ConfigureAll <HttpTracingOptions>(options =>
            {
                options.TagsOptions.Config.Name           = "name";
                options.TagsOptions.Config.Port           = "port";
                options.TagsOptions.Config.Schema         = "schema";
                options.TagsOptions.Config.MaxConnection  = "maxConnection";
                options.TagsOptions.Request.Schema        = "r.schema";
                options.TagsOptions.Request.RequestLength = "size";
                options.TagsOptions.Request.RequestPath   = "path";
                options.TagsOptions.Request.Host          = "host";

                // options.OnActivityEnd(context => _activities.Add(context));
            });

            serviceCollection
            .ConfigureAll <OpenTelemetryOptions>(options =>
            {
                options.ConfigureBuilder += builder => builder.AddProcessor(new NopProcessor());
                // options.ConfigureBuilder += builder => builder.AddConsoleExporter();
            });

            serviceCollection.AddHttpOptionsTelemetry();


            serviceCollection.AddHttpClientOptions(options =>
            {
                options.ServiceName           = "service";
                options.Handler.MaxConnection = 100;
                _server.ConfigureWireMockServer(options);
            });


            var factory   = serviceCollection.BuildServiceProvider().GetRequiredService <IHttpClientFactory>();
            var client    = factory.CreateClient("service");
            var stopwatch = Stopwatch.StartNew();

            var rateStats = await
                            TrafficGenerator
                            .GenerateTraffic(rate, () => client.GetAsync(endpoint))
                            .RPS()
                            .Stats()
                            .TakeUntil(DateTimeOffset.Now.AddSeconds(20));


            stopwatch.Stop();
            Console.WriteLine(rateStats.Print());

            Assert.That(rateStats.Success.Median, Is.GreaterThanOrEqualTo(rate).Within(within));
        }
Esempio n. 2
0
        public async Task HttpClient_DefaultConfigLatencyTests(string endpoint, int rate, int expectedLatency = 10,
                                                               int within = 10)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClientOptions(options =>
            {
                options.ServiceName = "service";
                _server.ConfigureWireMockServer(options);
            });

            var factory = serviceCollection.BuildServiceProvider().GetRequiredService <IHttpClientFactory>();
            var client  = factory.CreateClient("service");

            var latencyStats = await TrafficGenerator
                               .GenerateTraffic(rate, () => client.GetAsync(endpoint))
                               .Latency()
                               .TakeUntil(DateTimeOffset.Now.AddSeconds(20));

            Console.WriteLine(
                latencyStats.Print());

            Assert.That(latencyStats.Median, Is.EqualTo(expectedLatency).Within(within));
        }