Beispiel #1
0
        public static void Run()
        {
            // it's a very basic HTTP example, don't use it for production testing
            // for production purposes use NBomber.Http which use performance optimizations
            // you can find more here: https://github.com/PragmaticFlow/NBomber.Http

            var httpClient = new HttpClient();

            var step = Step.Create("GET_gitter_html", async context =>
            {
                var response = await httpClient.GetAsync(
                    "https://gitter.im",
                    context.CancellationToken);

                return(response.IsSuccessStatusCode
                    ? Response.Ok(sizeBytes: (int)response.Content.Headers.ContentLength.Value)
                    : Response.Fail());
            });

            var scenario = ScenarioBuilder.CreateScenario("test_gitter", step)
                           .WithConcurrentCopies(100);

            NBomberRunner.RegisterScenarios(scenario)
            .RunInConsole();
        }
Beispiel #2
0
        public static void Run()
        {
            var db = new MongoClient().GetDatabase("Test");
            var usersCollection = db.GetCollection <User>("Users");

            var step = Step.Create("query_users", async context =>
            {
                await usersCollection.Find(u => u.IsActive)
                .Limit(500)
                .ToListAsync(context.CancellationToken);

                return(Response.Ok());
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("mongo_scenario", step)
                           .WithInit(ScenarioInit)
                           .WithLoadSimulations(new []
            {
                Simulation.KeepConstant(copies: 100, during: TimeSpan.FromSeconds(30))
            });

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithTestSuite("mongo")
            .WithTestName("simple_query_test")
            .Run();
        }
        public void get_resources()
        {
            const string url         = "http://localhost:5001";
            const string stepName    = "init";
            const int    duration    = 3;
            const int    expectedRps = 100;
            var          endpoint    = $"{url}/resources";

            var step = HttpStep.Create(stepName, ctx =>
                                       Task.FromResult(Http.CreateRequest("GET", endpoint)
                                                       .WithCheck(response => Task.FromResult(response.IsSuccessStatusCode))));

            var assertions = new[]
            {
                Assertion.ForStep(stepName, s => s.RPS >= expectedRps),
                Assertion.ForStep(stepName, s => s.OkCount >= expectedRps * duration)
            };

            var scenario = ScenarioBuilder.CreateScenario("GET resources", step)
                           .WithConcurrentCopies(1)
                           .WithOutWarmUp()
                           .WithDuration(TimeSpan.FromSeconds(duration))
                           .WithAssertions(assertions);

            NBomberRunner.RegisterScenarios(scenario)
            .RunTest();
        }
Beispiel #4
0
        public static void Run()
        {
            var step = Step.Create("step", async context =>
            {
                await Task.Delay(TimeSpan.FromSeconds(0.1));
                return(Response.Ok(sizeBytes: 100));
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("simple_scenario", step)
                           .WithoutWarmUp()
                           .WithLoadSimulations(Simulation.KeepConstant(1, TimeSpan.FromMinutes(1)));

            var influxConfig = InfluxDbSinkConfig.Create("http://localhost:8086", dbName: "default");
            var influxDb     = new InfluxDBSink(influxConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithTestSuite("reporting")
            .WithTestName("influx_test")
            .WithReportingSinks(
                reportingSinks: new[] { influxDb },
                sendStatsInterval: TimeSpan.FromSeconds(10)
                )
            .Run();
        }
Beispiel #5
0
        public static void Run()
        {
            var step1 = Step.Create("step_1", async context =>
            {
                // you can do any logic here: go to http, websocket etc

                await Task.Delay(TimeSpan.FromMilliseconds(200));
                return(Response.Ok(42)); // this value will be passed as response for the next step
            });

            var step2 = Step.Create("step_2", async context =>
            {
                // you can do any logic here: go to http, websocket etc

                await Task.Delay(TimeSpan.FromMilliseconds(200));
                var value = context.GetPreviousStepResponse <int>(); // 42
                return(Response.Ok());
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("hello_world_scenario", new[] { step1, step2 })
                           .WithWarmUpDuration(TimeSpan.FromSeconds(10))
                           .WithLoadSimulations(new []
            {
                Simulation.RampConcurrentScenarios(copiesCount: 10, during: TimeSpan.FromSeconds(20)),
                Simulation.KeepConcurrentScenarios(copiesCount: 10, during: TimeSpan.FromMinutes(1)),
                // Simulation.RampScenariosPerSec(copiesCount: 10, during: TimeSpan.FromSeconds(20)),
                // Simulation.InjectScenariosPerSec(copiesCount: 10, during: TimeSpan.FromMinutes(1))
            });

            NBomberRunner
            .RegisterScenarios(new[] { scenario })
            .RunInConsole();
        }
Beispiel #6
0
        public void get_person()
        {
            const string url         = "https://localhost:5001";
            const string stepName    = "init";
            const int    duration    = 10;
            const int    expectedRps = 100;
            var          endpoint    = $"{url}/api/person/?id=3fa85f64-5717-4562-b3fc-2c963f66afa6";

            var step = HttpStep.Create(stepName, ctx =>
                                       Task.FromResult(Http.CreateRequest("GET", endpoint)
                                                       .WithCheck(response => Task.FromResult(response.IsSuccessStatusCode))));

            var assertions = new[]
            {
                Assertion.ForStep(stepName, s => s.RPS >= expectedRps),
                Assertion.ForStep(stepName, s => s.OkCount >= expectedRps * duration)
            };

            var scenario = ScenarioBuilder.CreateScenario("GET single person", new[] { step })
                           .WithConcurrentCopies(1)
                           .WithOutWarmUp()
                           .WithDuration(TimeSpan.FromSeconds(duration))
                           .WithAssertions(assertions);

            NBomberRunner.RegisterScenarios(scenario)
            .RunTest();
        }
        public void get_game_event_sources()
        {
            //Arrange
            const string url         = "http://localhost:7001";
            const string stepName    = "init";
            const int    duration    = 3;
            const int    expectedRps = 100; //100 RPS
            var          endpoint    = $"{url}/game-event-sources";

            var step = HttpStep.Create(stepName, ctx =>
                                       Task.FromResult(Http.CreateRequest("GET", endpoint)
                                                       .WithCheck(response => Task.FromResult(response.IsSuccessStatusCode))));

            //Assert
            var assertions = new[]
            {
                Assertion.ForStep(stepName, s => s.RPS >= expectedRps), //we expected 100 rps but we serve 530 rps and this step will pass
                Assertion.ForStep(stepName, s => s.OkCount >= expectedRps * duration)
            };

            //Act
            var scenario = ScenarioBuilder.CreateScenario("GET game-event-sources", new[] { step })
                           .WithConcurrentCopies(1)
                           .WithOutWarmUp()
                           .WithDuration(TimeSpan.FromSeconds(duration))
                           .WithAssertions(assertions);

            NBomberRunner.RegisterScenarios(scenario)
            .RunTest();
        }
Beispiel #8
0
        public static void Run()
        {
            var data = new[] { 1, 2, 3, 4, 5 }.ShuffleData();
            //var data = FeedData.FromJson<User>("./DataFeed/users-feed-data.json");
            //var data = FeedData.FromCsv<User>("./DataFeed/users-feed-data.csv");

            var feed = Feed.CreateCircular("numbers", data);

            // lazy
            //var feed = Feed.CreateCircular("numbers", getData: () => data);

            //var feed = Feed.CreateConstant("numbers", data);
            //var feed = Feed.CreateRandom("numbers", data);

            var step = Step.Create("step", feed, async context =>
            {
                await Task.Delay(Seconds(1));

                context.Logger.Debug("Data from feed: {FeedItem}", context.FeedItem);
                return(Response.Ok());
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("data_feed_scenario", step)
                           .WithLoadSimulations(Simulation.KeepConstant(1, TimeSpan.FromSeconds(1)));

            NBomberRunner
            .RegisterScenarios(scenario)
            .Run();
        }
        public static void Run()
        {
            var httpFactory = HttpClientFactory.Create();

            var step1 = Step.Create("step 1", clientFactory: httpFactory, execute: async context =>
            {
                var request  = Http.CreateRequest("GET", "https://gitter.im");
                var response = await Http.Send(request, context);
                return(response);
            });

            var step2 = Step.Create("step 2", clientFactory: httpFactory, execute: async context =>
            {
                var step1Response = context.GetPreviousStepResponse <HttpResponseMessage>();
                var headers       = step1Response.Headers;
                var body          = await step1Response.Content.ReadAsStringAsync();

                var request  = Http.CreateRequest("GET", "https://gitter.im");
                var response = await Http.Send(request, context);
                return(response);
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("test_gitter", step1, step2)
                           .WithoutWarmUp()
                           .WithLoadSimulations(Simulation.InjectPerSec(100, TimeSpan.FromSeconds(30)));

            NBomberRunner
            .RegisterScenarios(scenario)
            .Run();
        }
Beispiel #10
0
        public static void Run()
        {
            // in this example we use NBomber.Http package which simplifies writing HTTP requests
            // you can find more here: https://github.com/PragmaticFlow/NBomber.Http

            var step = HttpStep.Create("http pull", context =>
                                       Http.CreateRequest("GET", "https://nbomber.com")
                                       .WithHeader("Accept", "text/html")
                                       //.WithHeader("Cookie", "cookie1=value1; cookie2=value2")
                                       //.WithBody(new StringContent("{ some JSON }", Encoding.UTF8, "application/json"))
                                       //.WithCheck(response => Task.FromResult(response.IsSuccessStatusCode))
                                       );

            var scenario = ScenarioBuilder.CreateScenario("test_nbomber", new[] { step })
                           .WithWarmUpDuration(TimeSpan.FromSeconds(10))
                           .WithLoadSimulations(new[]
            {
                Simulation.InjectScenariosPerSec(copiesCount: 100, during: TimeSpan.FromSeconds(30))
            });

            var pingPluginConfig = PingPluginConfig.Create(new[] { "nbomber.com" });
            var pingPlugin       = new PingPlugin(pingPluginConfig);

            NBomberRunner
            .RegisterScenarios(new[] { scenario })
            .WithPlugins(new[] { pingPlugin })
            .RunInConsole();
        }
        public static void Run()
        {
            var step = HttpStep.Create("fetch_html_page", context =>
                                       Http.CreateRequest("GET", "https://nbomber.com")
                                       .WithHeader("Accept", "text/html")
                                       );

            var scenario = ScenarioBuilder
                           .CreateScenario("nbomber_web_site", step)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(5))
                           .WithLoadSimulations(new[]
            {
                Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(30))
            });

            var pingPluginConfig = PingPluginConfig.CreateDefault(new[] { "nbomber.com" });
            var pingPlugin       = new PingPlugin(pingPluginConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithPlugins(pingPlugin)
            .WithTestSuite("http")
            .WithTestName("tracing_test")
            .WithLoggerConfig(() => new LoggerConfiguration().MinimumLevel.Verbose())     // set log to verbose
            .Run();
        }
Beispiel #12
0
        public static void Run()
        {
            var step = Step.Create("step", async context =>
            {
                await Task.Delay(Seconds(0.1));

                context.Logger.Debug(
                    "step received CustomSettings.TestField '{TestField}'",
                    _customSettings.TestField
                    );

                return(Response.Ok()); // this value will be passed as response for the next step
            });

            var customPause = Step.CreatePause(() => _customSettings.PauseMs);

            var scenario = ScenarioBuilder
                           .CreateScenario("my_scenario", step, customPause)
                           .WithInit(ScenarioInit);

            NBomberRunner
            .RegisterScenarios(scenario)
            .LoadConfig("./HelloWorld/config.json")
            .Run();
        }
        public static void Run()
        {
            var step = Step.Create("step", async context =>
            {
                await Task.Delay(TimeSpan.FromSeconds(1));

                // this message will be saved to elastic search
                context.Logger.Debug("hello from NBomber");

                return(Response.Ok());
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("scenario", step)
                           .WithoutWarmUp()
                           .WithLoadSimulations(new[]
            {
                Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(30))
            });

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithTestSuite("logging")
            .WithTestName("elastic_search")
            .LoadInfraConfig("./Logging/infra-config.json")
            .Run();
        }
Beispiel #14
0
        public static void Run()
        {
            var httpFactory = HttpClientFactory.Create();

            var step = Step.Create("simple step", clientFactory: httpFactory, execute: async context =>
            {
                var request =
                    Http.CreateRequest("GET", "https://nbomber.com")
                    .WithHeader("Accept", "text/html")
                    .WithBody(new StringContent("{ some JSON }"))
                    .WithCheck(async(response) =>
                               //response.ToNBomberResponse() - you can convert HttpResponseMessage to NBomber's Response
                               response.IsSuccessStatusCode
                                ? Response.Ok()
                                : Response.Fail()
                               );

                var response = await Http.Send(request, context);
                return(response);
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("test_gitter", step)
                           .WithoutWarmUp()
                           .WithLoadSimulations(Simulation.InjectPerSec(100, TimeSpan.FromSeconds(30)));

            NBomberRunner
            .RegisterScenarios(scenario)
            .Run();
        }
Beispiel #15
0
        public async void ExploreSolution_GetAllReservations_LoadTest()
        {
            string   baseUrl        = "https://exploresolutionapi.azurewebsites.net";
            string   loginUrl       = baseUrl + "/api/Authentication/request";
            string   getAllToursUrl = baseUrl + "/api/reservations/GetAllReservations";
            TimeSpan warmUp         = TimeSpan.FromMinutes(1);

            IStep loginStep = Auth(loginUrl);

            var getAllReservations = HttpStep.Create("getReservations", async(context) =>
            {
                var responseContent = context.Data as HttpResponseMessage;
                var authToken       = await responseContent.Content.ReadAsStringAsync();
                return(Http.CreateRequest("GET", getAllToursUrl)
                       .WithHeader("Authorization", $"Bearer {authToken}"));
                //.WithCheck(async response =>
                //{
                //    return response.IsSuccessStatusCode ? Response.Ok() : Response.Fail();
                //});
            });

            var influxConfig = InfluxDbSinkConfig.Create("https://westeurope-1.azure.cloud2.influxdata.com", dbName: "*****@*****.**");
            var influxDb     = new InfluxDBSink(influxConfig);

            var scenario = ScenarioBuilder.CreateScenario("Get All Reservations", new[] { loginStep, getAllReservations })
                           .WithWarmUpDuration(warmUp)
                           .WithLoadSimulations(new[]
            {
                Simulation.RampPerSec(10, TimeSpan.FromMinutes(1))
            });

            var nodeStats = NBomberRunner.RegisterScenarios(scenario).Run();
        }
Beispiel #16
0
        public static void Run()
        {
            var step1 = Step.Create("step_1", async context =>
            {
                // you can do any logic here: go to http, websocket etc

                await Task.Delay(Seconds(0.1));
                return(Response.Ok(42)); // this value will be passed as response for the next step
            });

            var pause = Step.CreatePause(Milliseconds(100));

            var step2 = Step.Create("step_2", async context =>
            {
                var value = context.GetPreviousStepResponse <int>(); // 42
                return(Response.Ok());
            });

            // here you create scenario and define (default) step order
            // you also can define them in opposite direction, like [step2; step1]
            // or even repeat [step1; step1; step1; step2]
            var scenario = ScenarioBuilder
                           .CreateScenario("hello_world_scenario", step1, pause, step2)
                           .WithoutWarmUp()
                           .WithLoadSimulations(
                Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(30))
                );

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithTestSuite("example")
            .WithTestName("hello_world_test")
            .Run();
        }
Beispiel #17
0
        public static void Run()
        {
            var step = HttpStep.Create("fetch_html_page", context =>
                                       Http.CreateRequest("GET", "https://nbomber.com")
                                       .WithHeader("Accept", "text/html")
                                       );

            var scenario = ScenarioBuilder
                           .CreateScenario("nbomber_web_site", step)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(5))
                           .WithLoadSimulations(new[]
            {
                Simulation.InjectPerSec(rate: 100, during: TimeSpan.FromSeconds(30))
            });

            var pingPluginConfig = PingPluginConfig.CreateDefault(new[] { "nbomber.com" });
            var pingPlugin       = new PingPlugin(pingPluginConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithWorkerPlugins(pingPlugin)
            .WithTestSuite("http")
            .WithTestName("simple_test")
            .Run();
        }
Beispiel #18
0
        public static void Run()
        {
            var db = new MongoClient().GetDatabase("Test");

            Task initDb(ScenarioContext context)
            {
                var testData = Enumerable.Range(0, 2000)
                               .Select(i => new User {
                    Name = $"Test User {i}", Age = i, IsActive = true
                })
                               .ToList();

                db.DropCollection("Users", context.CancellationToken);
                return(db.GetCollection <User>("Users")
                       .InsertManyAsync(testData, cancellationToken: context.CancellationToken));
            }

            var usersCollection = db.GetCollection <User>("Users");

            var step = Step.Create("read IsActive = true and TOP 500", async context =>
            {
                await usersCollection.Find(u => u.IsActive)
                .Limit(500)
                .ToListAsync(context.CancellationToken);
                return(Response.Ok());
            });

            var scenario = ScenarioBuilder.CreateScenario("test_mongo", step)
                           .WithTestInit(initDb);

            NBomberRunner.RegisterScenarios(scenario)
            .RunInConsole();
        }
Beispiel #19
0
        public async void ExploreSolution_GetAllTours_LoadTest()
        {
            string baseUrl        = "https://exploresolutionapi.azurewebsites.net";
            string loginUrl       = baseUrl + "/api/Authentication/request";
            string getAllToursUrl = baseUrl + "/api/tours/getAll";

            IStep loginStep = Auth(loginUrl);

            var getAllTours = HttpStep.Create("getAllTours", async(context) =>
            {
                var responseContent = context.Data as HttpResponseMessage;
                var authToken       = await responseContent.Content.ReadAsStringAsync();
                return(Http.CreateRequest("GET", getAllToursUrl)
                       .WithHeader("Authorization", $"Bearer {authToken}")
                       .WithCheck(async response =>
                {
                    return response.IsSuccessStatusCode ? Response.Ok() : Response.Fail();
                }));
            });


            var scenario = ScenarioBuilder.CreateScenario("Get All Tours", new[] { loginStep, getAllTours })
                           .WithoutWarmUp()
                           .WithLoadSimulations(new[]
            {
                Simulation.KeepConstant(1, TimeSpan.FromMinutes(1))
            });

            var nodeStats = NBomberRunner.RegisterScenarios(scenario).Run();
        }
Beispiel #20
0
        public static void Run()
        {
            var httpFactory = HttpClientFactory.Create();

            var step = Step.Create("fetch_html_page",
                                   clientFactory: httpFactory,
                                   execute: async context =>
            {
                var response = await context.Client.GetAsync("https://nbomber.com", context.CancellationToken);

                return(response.IsSuccessStatusCode
                    ? Response.Ok(statusCode: (int)response.StatusCode)
                    : Response.Fail(statusCode: (int)response.StatusCode));
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("simple_http", step)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(5))
                           .WithLoadSimulations(new[]
            {
                Simulation.InjectPerSec(rate: 100, during: TimeSpan.FromSeconds(30))
            });

            var pingPluginConfig = PingPluginConfig.CreateDefault(new[] { "nbomber.com" });
            var pingPlugin       = new PingPlugin(pingPluginConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithWorkerPlugins(pingPlugin)
            .Run();
        }
Beispiel #21
0
        public static void Run()
        {
            var httpFactory = HttpClientFactory.Create();

            var step = Step.Create("fetch_html_page",
                                   clientFactory: httpFactory,
                                   execute: async context =>
            {
                var response = await context.Client.GetAsync("https://nbomber.com", context.CancellationToken);

                return(response.IsSuccessStatusCode
                    ? Response.Ok(statusCode: (int)response.StatusCode)
                    : Response.Fail(statusCode: (int)response.StatusCode));
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("nbomber_web_site", step)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(5))
                           .WithLoadSimulations(new[]
            {
                Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(30))
            });

            var pingPluginConfig = PingPluginConfig.CreateDefault(new[] { "nbomber.com" });
            var pingPlugin       = new PingPlugin(pingPluginConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithWorkerPlugins(pingPlugin)
            .WithTestSuite("http")
            .WithTestName("tracing_test")
            .WithLoggerConfig(() => new LoggerConfiguration().MinimumLevel.Verbose())     // set log to verbose
            .Run();
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            var scenario = BuildScenario();

            NBomberRunner.RegisterScenarios(scenario)
            .RunInConsole();
        }
        public void AddNew()
        {
            //Arrange
            AddNewCarRequest addNewCarRequest = new AddNewCarRequest("BMW", 1999);
            string           json             = JsonSerializer.Serialize(addNewCarRequest);
            StringContent    content          = new StringContent(json, Encoding.UTF8, "application/json");

            var step = HttpStep.Create("addNew", ctx =>
                                       Task.FromResult(Http.CreateRequest("POST", endpoint)
                                                       .WithBody(content)
                                                       ));

            var scenario = ScenarioBuilder.CreateScenario("Add", step)
                           .WithoutWarmUp()
                           .WithLoadSimulations(Simulation.KeepConstant(2, TimeSpan.FromSeconds(30)));

            //Act
            NodeStats nodeStats = NBomberRunner.RegisterScenarios(scenario).Run();

            //Assert
            nodeStats.OkCount.Should().Be(nodeStats.RequestCount);
            StepStats stepStats = nodeStats.ScenarioStats[0].StepStats[0];

            stepStats.RPS.Should().BeGreaterOrEqualTo(1500);
        }
Beispiel #24
0
 static void Main(string[] args)
 {
     NBomberRunner
     .RegisterScenarios(DapperConnectionPoolingScenarioFactory.Build())
     .WithTestName("ModularMonolith - Performance tests")
     .WithReportFormats(ReportFormat.Html)
     .Run();
 }
Beispiel #25
0
        public static void Run()
        {
            var url = "ws://localhost:5000";
            var concurrentCopies = 50;

            var webSocketsPool = ConnectionPool.Create(
                name: "webSocketsPool",
                connectionsCount: concurrentCopies,
                openConnection: (number) =>
            {
                var ws = new ClientWebSocket();
                ws.ConnectAsync(new Uri(url), CancellationToken.None).Wait();
                return(ws);
            },
                closeConnection: (connection) =>
            {
                connection.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None)
                .Wait();
            }
                );

            var pingStep = Step.Create("ping", webSocketsPool, async context =>
            {
                var msg = new WebSocketRequest
                {
                    CorrelationId = context.CorrelationId.Id,
                    RequestType   = RequestType.Ping
                };
                var bytes = MsgConverter.ToJsonByteArray(msg);
                await context.Connection.SendAsync(bytes, WebSocketMessageType.Text, true, context.CancellationToken);
                return(Response.Ok());
            });

            var pongStep = Step.Create("pong", webSocketsPool, async context =>
            {
                while (true)
                {
                    var(response, message) = await WebSocketsMiddleware.ReadFullMessage(context.Connection, context.CancellationToken);
                    var msg = MsgConverter.FromJsonByteArray <WebSocketResponse>(message);

                    if (msg.CorrelationId == context.CorrelationId.Id)
                    {
                        return(Response.Ok(msg));
                    }
                }
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("web_socket test", new[] { pingStep, pongStep })
                           .WithOutWarmUp()
                           .WithLoadSimulations(new[]
            {
                Simulation.KeepConcurrentScenarios(concurrentCopies, during: TimeSpan.FromSeconds(10))
            });

            NBomberRunner.RegisterScenarios(scenario)
            .RunInConsole();
        }
        protected void ExecuteLoadTests(params IStep[] steps)
        {
            var scenario = CreateScenario(steps);

            var stats = NBomberRunner.RegisterScenarios(new[] { scenario })
                        .RunTest();

            AssertResults(stats);
        }
Beispiel #27
0
        public static void Run()
        {
            var userFeed = Feed.CreateRandom(
                name: "userFeed",
                provider: FeedData.FromJson <UserId>("./HttpTests/Configs/user-feed.json")
                );

            var getUser = HttpStep.Create("get_user", userFeed, context =>
            {
                var userId = context.FeedItem;
                var url    = $"https://jsonplaceholder.typicode.com/users?id={userId}";

                return(Http.CreateRequest("GET", url)
                       .WithCheck(async response =>
                {
                    var json = await response.Content.ReadAsStringAsync();

                    // parse JSON
                    var users = JsonConvert.DeserializeObject <UserResponse[]>(json);

                    return users?.Length == 1
                            ? Response.Ok(users.First()) // we pass user object response to the next step
                            : Response.Fail("not found user");
                }));
            });

            // this 'getPosts' will be executed only if 'getUser' finished OK.
            var getPosts = HttpStep.Create("get_posts", context =>
            {
                var user = context.GetPreviousStepResponse <UserResponse>();
                var url  = $"https://jsonplaceholder.typicode.com/posts?userId={user.Id}";

                return(Http.CreateRequest("GET", url)
                       .WithCheck(async response =>
                {
                    var json = await response.Content.ReadAsStringAsync();

                    // parse JSON
                    var posts = JsonConvert.DeserializeObject <PostResponse[]>(json);

                    return posts?.Length > 0
                            ? Response.Ok()
                            : Response.Fail($"not found posts for user: {user.Id}");
                }));
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("rest_api", getUser, getPosts);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithWorkerPlugins(new PingPlugin())
            .LoadConfig("./HttpTests/Configs/config.json")
            .LoadInfraConfig("./HttpTests/Configs/infra-config.json")
            .Run();
        }
        static void Main(string[] args)
        {
            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default");

            var scenario = BuildScenario();

            NBomberRunner.RegisterScenarios(scenario)
            .SaveStatisticsTo(influxDb)
            .RunInConsole();
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            var scenarios = new JsonRpcScenarios();

            NBomberRunner.RegisterScenarios(
                scenarios.eth_blockNumber,
                scenarios.eth_getBalance,
                scenarios.eth_getBlockByNumber)
            .RunInConsole();
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Load testing via Bomber");
            Console.WriteLine("---------------------------------------------------------------");

            var scenario = BomberScenarioLibrary.OrderScenario;

            NBomberRunner
            .RegisterScenarios(scenario)
            .Run();
        }