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 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(); }
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(); }
public PingMiddleware(IMiddleware next, PingPlugin pingPlugin) : base(next) { _pingPlugin = pingPlugin; HandlerMappings = new[] { new HandlerMapping { ValidHandles = new [] { "ping stop", "stop pinging me" }, Description = "Stops sending you pings", EvaluatorFunc = StopPingingHandler }, new HandlerMapping { ValidHandles = new [] { "ping list" }, Description = "Lists all of the people currently being pinged", EvaluatorFunc = ListPingHandler }, new HandlerMapping { ValidHandles = new [] { "ping me" }, Description = "Sends you a ping about every second", EvaluatorFunc = PingHandler }, }; }
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(); }
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(); }
static void Main(string[] args) { PingPluginOptions Options = new PingPluginOptions(); Options.label = "Ping"; Options.units = "%,ms"; Options.ProcessArgs(args); PingPlugin plugin = new PingPlugin(Options); MultiPingReply reply = plugin.Ping(); plugin.AppendValue("Packet Loss", reply.PacketLoss); plugin.AppendValue("RTA", reply.RoundTripTimeAverage); plugin.Finish(); }
public static void Run() { var userFeed = Feed.CreateRandom( name: "userFeed", provider: FeedData.FromSeq(new[] { "1", "2", "3", "4", "5" }) ); 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: {userId}"); })); }); // 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) .WithWarmUpDuration(TimeSpan.FromSeconds(5)) .WithLoadSimulations(new[] { Simulation.InjectPerSec(rate: 100, during: TimeSpan.FromSeconds(30)) }); var pingPluginConfig = PingPluginConfig.CreateDefault(new[] { "jsonplaceholder.typicode.com" }); var pingPlugin = new PingPlugin(pingPluginConfig); NBomberRunner .RegisterScenarios(scenario) .WithPlugins(pingPlugin) .WithTestSuite("http") .WithTestName("advanced_test") .Run(); }
static void Main(string[] args) { IFeed <RequestInfo> urlsDataFeed = Feed.CreateConstant("Requests", FeedData.FromSeq(relativeUrlsToTest)); IStep relativeUrlsHttpRequestStep = HttpStep.Create( name: $"Fetch random Ebriza data intensive URLs", feed: urlsDataFeed, ctx => { string cookies = httpClientHandler.CookieContainer.GetCookieHeader(new Uri($"{webProtocol}{webDomain}")); NBomber.Http.HttpRequest result = Http.CreateRequest(ctx.FeedItem.Method, $"{webProtocol}{webDomain}{ctx.FeedItem.RelativeUrl}") .WithHeader("Cookie", cookies) .WithCheck(async res => res.IsSuccessStatusCode && res.RequestMessage.RequestUri.ToString().Contains(ctx.FeedItem.RelativeUrl, StringComparison.InvariantCultureIgnoreCase) ? Response.Ok() : Response.Fail(res.StatusCode.ToString())) ; if (ctx.FeedItem.Body != null) { result = result.WithBody(new StringContent(JsonConvert.SerializeObject(ctx.FeedItem.Body), Encoding.UTF8, ctx.FeedItem.ContentType)); } return(result); }, completionOption: HttpCompletionOption.ResponseContentRead ); NBomber.Contracts.Scenario userPerSecondScenario = ScenarioBuilder .CreateScenario(name: $"Load Testing Scenario for {webDomain} with {usersPerSecondToSimulate} users per second", relativeUrlsHttpRequestStep) .WithWarmUpDuration(defaultWarmupDuration) .WithInit(async ctx => { using (HttpResponseMessage response = await http.PostAsync( $"{webProtocol}{webDomain}/Login/Login", new StringContent( JsonConvert.SerializeObject( new { CompanyHandle = companyHandle, UserName = username, Password = password, } ), Encoding.UTF8, "application/json" ) ) ) { response.EnsureSuccessStatusCode(); }; }) .WithClean(ctx => { http.CancelPendingRequests(); httpClientHandler.Dispose(); http.Dispose(); return(System.Threading.Tasks.Task.CompletedTask); }) .WithLoadSimulations(new NBomber.Contracts.LoadSimulation[] { Simulation.InjectPerSec(rate: usersPerSecondToSimulate, during: defaultSimulationDuration), //RATE scenarios per second, for a timespan of DURING seconds) }); PingPluginConfig pingPluginConfig = PingPluginConfig.CreateDefault(new string[] { webDomain }); PingPlugin pingPlugin = new PingPlugin(pingPluginConfig); NBomberRunner .RegisterScenarios(userPerSecondScenario) .WithTestSuite("Ebriza Load Testing") .WithTestName($"Load test {webDomain}") .WithWorkerPlugins(pingPlugin) .Run(); }
public static void Run() { var userFeed = Feed.CreateRandom( "userFeed", FeedData.FromJson <User>("./JsonConfig/Configs/user-feed.json") ); var httpFactory = ClientFactory.Create("http_factory", initClient: (number, context) => Task.FromResult(new HttpClient { BaseAddress = new Uri(_customSettings.BaseUri) })); var getUser = Step.Create("get_user", httpFactory, userFeed, async context => { var userId = context.FeedItem; var url = $"users?id={userId}"; var response = await context.Client.GetAsync(url, context.CancellationToken); 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 = Step.Create("get_posts", httpFactory, async context => { var user = context.GetPreviousStepResponse <UserResponse>(); var url = $"posts?userId={user.Id}"; var response = await context.Client.GetAsync(url, context.CancellationToken); var json = await response.Content.ReadAsStringAsync(); // parse JSON var posts = JsonConvert.DeserializeObject <PostResponse[]>(json); return(posts?.Length > 0 ? Response.Ok() : Response.Fail()); }); var scenario1 = ScenarioBuilder .CreateScenario("rest_api", getUser, getPosts) .WithInit(ScenarioInit); // the following scenario will be ignored since it is not included in target scenarios list of config.json var scenario2 = ScenarioBuilder .CreateScenario("ignored", getUser, getPosts); // settings for worker plugins and reporting sinks are overriden in infra-config.json var pingPlugin = new PingPlugin(); var customPlugin = new CustomPlugin(new CustomPluginSettings { Message = "Plugin is configured via constructor" }); var influxDbReportingSink = new InfluxDBSink(); var customReportingSink = new CustomReportingSink(new CustomReportingSinkSettings { Message = "Reporting sink is configured via constructor" }); NBomberRunner .RegisterScenarios(scenario1, scenario2) .WithWorkerPlugins(pingPlugin, customPlugin) .WithReportingSinks(influxDbReportingSink, customReportingSink) .LoadConfig("./JsonConfig/Configs/config.json") .LoadInfraConfig("./JsonConfig/Configs/infra-config.json") .Run(); }