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(); }
public void Post_with_Get_load_test() { const string request = @"{ ""firstName"": ""load"", ""lastName"": ""test"", ""gender"": ""M"", ""birthDate"": ""1980-11-11"" }"; var post = CreateStep("/", "POST", request.ToStringContent()); var get = HttpStep.Create("get emp", async ctx => { var response = ctx.GetPreviousStepResponse <HttpResponseMessage>(); var content = await response.Content.ReadAsStringAsync(); var emp = content.Deserialize <EmployeeDto>(); Trace.WriteLine($"The previous step created employee with Id = {emp.Id}"); var getUrl = response.Headers.Location; return(Http.CreateRequest("GET", getUrl.ToString()) .WithHeader("Authorization", "ApiKey ABC-xyz") .WithCheck(response => Task.FromResult(response.GetCheckResult()))); }); ExecuteLoadTests(post, get); }
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(); }
private async Task <HttpResponseMessage> MakeHttpRequestAsync(HttpStep step, Item item) { HttpClient httpClient = new HttpClient(); HttpResponseMessage httpResponseMessage = null; switch (step.HttpMethod) { case "GET": { httpResponseMessage = await httpClient.GetAsync(step.Url); break; } case "POST": { throw new NotImplementedException(); } case "DELETE": { throw new NotImplementedException(); } case "PATCH": { throw new NotImplementedException(); } } return(httpResponseMessage); }
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(); }
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(); }
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.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(); }
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_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(); }
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); }
/// <summary> /// Creates a simple step /// </summary> /// <param name="url"></param> /// <param name="data"></param> /// <returns></returns> public static HttpStep CreateHttpStep(this ProcessBuilder builder, string url) { var step = new HttpStep(url, HttpMethod.Get, new { }); step.SetOptions(StepOptions.Default); return(step); }
public HttpSendingResponseArgs(HttpContext httpContext, SyncContext context, SessionCache sessionCache, byte[] data, HttpStep httpStep) : base(context, null, null) { this.HttpContext = httpContext; this.SessionCache = sessionCache; this.Data = data; this.HttpStep = httpStep; }
protected static Scenario CreateGetScenario(string nameScenatio, string uri) { var step = HttpStep.Create("Request step", context => Http.CreateRequest("GET", Constants.MovieService.Url + uri)); return(ScenarioBuilder .CreateScenario(nameScenatio, new[] { step }) .WithConcurrentCopies(10) .WithDuration(TimeSpan.FromSeconds(10))); }
public static Scenario Create() { var step = HttpStep.Create("pull home page", (context) => Http.CreateRequest("GET", "https://nbomber.com") .WithHeader("Accept", "text/html") ); return(ScenarioBuilder.CreateScenario("simple http scenario", new[] { step })); }
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(); }
/// <summary> /// Creates a simple HTTP step /// </summary> /// <param name="url"></param> /// <param name="method"></param> /// <param name="data"></param> /// <returns></returns> public static HttpStep CreateHttpStep(this ProcessBuilder builder, string url, HttpMethod method, object data, StepOptions options = null) { options = options ?? StepOptions.Default; var step = new HttpStep(url, method, data); step.SetOptions(options); return(step); }
static Scenario BuildScenario() { var step = HttpStep.CreateRequest("GET", "https://www.youtube.com") .WithHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36") .BuildStep("GET request"); return(ScenarioBuilder.CreateScenario("youtube_scenario", step) .WithConcurrentCopies(10) .WithDuration(TimeSpan.FromSeconds(10))); }
private IStep GetStep(string url, string method, HttpContent body) { var stepName = $"{method} '{url}'"; return(HttpStep.Create(stepName, ctx => Http.CreateRequest(method, url) .WithHeader("Authorization", "ApiKey ABC-xyz") .WithBody(body) .WithCheck(response => Task.FromResult(response.IsSuccessStatusCode)) )); }
public async Task <IActionResult> Get() { HttpStep httpStep = HttpStep.CreateGetStep("label", null, "https://google.com"); ItemProcess itemProcess = new ItemProcess("desc", "label", 1, new List <Step>() { httpStep }); await itemProcessRepository.AddAsync(itemProcess); await itemProcessRepository.SaveAsync(); return(Ok()); }
public static void Run() { var step = HttpStep.Create("simple step", (context) => Http.CreateRequest("GET", "https://gitter.im") .WithHeader("Accept", "text/html") ); var scenario = ScenarioBuilder.CreateScenario("test_gitter", new[] { step }); NBomberRunner.RegisterScenarios(scenario) .LoadTestConfig("test_config.json") .RunInConsole(); }
/// <summary> /// Adds a step to the process that executes a request with the given method and data /// </summary> /// <param name="url"></param> /// <param name="method"></param> /// <param name="data"></param> /// <param name="reference"></param> /// <returns>Returns a reference code to the step created</returns> public static ProcessBuilder AddStep(this ProcessBuilder builder, string url, HttpMethod method, object data, out Guid reference, StepOptions options = null) { options = options ?? StepOptions.Default; var step = new HttpStep(url, method, data); step.SetOptions(options); reference = step.Reference; builder.Steps.Add(step); return(builder); }
protected NodeStats RunScenario(string name, Func <HttpRequest> request, int parallelCopies = 100, TimeSpan?period = null) { var step = HttpStep.Create("init", ctx => Task.FromResult(request())); var scenario = ScenarioBuilder.CreateScenario(name, step) .WithWarmUpDuration(TimeSpan.FromSeconds(3)) .WithLoadSimulations(LoadSimulation.NewKeepConstant(parallelCopies, period ?? TimeSpan.FromSeconds(10))); var stats = NBomberRunner.RegisterScenarios(scenario).Run(); var jsonStats = JsonSerializer.Serialize(stats); Output.WriteLine(jsonStats); return(stats); }
private Scenario Build(string method, object[] @params = null) { var request = new JsonRpcRequest(method, @params); var json = System.Text.Json.JsonSerializer.Serialize(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var step = HttpStep.Create(method, ctx => Task.FromResult(Http.CreateRequest("POST", _url) .WithHeader("content-type", "application/json") .WithBody(content) .WithCheck(response => Task.FromResult(response.IsSuccessStatusCode)))); return(ScenarioBuilder.CreateScenario($"Nethermind -> {method}()", step) .WithConcurrentCopies(100) .WithDuration(TimeSpan.FromSeconds(10))); }
static Scenario BuildScenario() { var step = HttpStep.CreateRequest("GET", "https://nbomber.com") .WithHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36") .BuildStep("GET request"); //.WithVersion("2.0") //.WithBody(new StringContent("{ some json }")) //.WithBody(new ByteArrayContent()) return(ScenarioBuilder.CreateScenario("test nbomber.com", step) .WithConcurrentCopies(50) .WithDuration(TimeSpan.FromSeconds(10))); }
static void Main(string[] args) { var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "NBomberDb"); var step = HttpStep.Create("simple step", (context) => Http.CreateRequest("GET", "https://nbomber.com") ); var scenario = ScenarioBuilder.CreateScenario("test_nbomber", new[] { step }) .WithConcurrentCopies(100) .WithWarmUpDuration(TimeSpan.FromSeconds(10)) .WithDuration(TimeSpan.FromMinutes(3)); NBomberRunner.RegisterScenarios(scenario) .WithReportingSinks(new[] { influxDb }, TimeSpan.FromSeconds(20)) .RunInConsole(); }
public static void Run() { 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 }) .WithConcurrentCopies(100) .WithWarmUpDuration(TimeSpan.FromSeconds(10)) .WithDuration(TimeSpan.FromSeconds(20)); NBomberRunner.RegisterScenarios(scenario) .RunInConsole(); }
public static void Run(string configPath) { var step = HttpStep.Create("simple step", (context) => Http.CreateRequest("GET", "https://gitter.im") .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_gitter", step); NBomberRunner.RegisterScenarios(scenario) .LoadConfig(configPath) //.LoadConfig("agent_config.json") //.LoadConfig("coordinator_config.json") .RunInConsole(); }
public static void Run() { var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default"); var step = HttpStep.Create("simple step", (context) => Http.CreateRequest("GET", "https://gitter.im") .WithHeader("Accept", "text/html") ); var scenario = ScenarioBuilder.CreateScenario("test_gitter", step) .WithConcurrentCopies(50) .WithWarmUpDuration(TimeSpan.FromSeconds(10)) .WithDuration(TimeSpan.FromSeconds(180)); NBomberRunner.RegisterScenarios(scenario) .SaveStatisticsTo(influxDb) .RunInConsole(); }
public static void Run() { var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default"); var step = HttpStep.Create("simple step", context => Http.CreateRequest("GET", "https://nbomber.com") .WithHeader("Accept", "text/html") ); var scenario = ScenarioBuilder.CreateScenario("test_nbomber", new[] { step }) .WithConcurrentCopies(50) .WithWarmUpDuration(TimeSpan.FromSeconds(10)) .WithDuration(TimeSpan.FromSeconds(180)); NBomberRunner.RegisterScenarios(scenario) .WithReportingSinks(new[] { influxDb }, sendStatsInterval: TimeSpan.FromSeconds(20)) .RunInConsole(); }