Giter Site home page Giter Site logo

abstracta / jmeter-dotnet-dsl Goto Github PK

View Code? Open in Web Editor NEW
35.0 5.0 1.0 1.26 MB

Simple JMeter performance tests .Net API

Home Page: https://abstracta.github.io/jmeter-dotnet-dsl/

License: Apache License 2.0

C# 100.00%
azure csharp dotnet jmeter jmx performance performance-testing

jmeter-dotnet-dsl's Introduction

logo

Simple .Net API to run performance tests, using JMeter as engine, in a Git and programmers friendly way.

If you like this project, please give it a star โญ! This helps the project be more visible, gain relevance, and encourage us to invest more effort in new features.

Here, you can find the Java DSL.

Please join discord server or create GitHub issues and discussions to be part of the community and clear out doubts, get the latest news, propose ideas, report issues, etc.

Usage

Add the package to your project:

dotnet add package Abstracta.JmeterDsl --version 0.5

Here is a simple example test using Nunit+ with 2 threads/users iterating 10 times each to send HTTP POST requests with a JSON body to http://my.service:

using System.Net.Http.Headers;
using System.Net.Mime;
using static Abstracta.JmeterDsl.JmeterDsl;

public class PerformanceTest
{
    [Test]
    public void LoadTest()
    {
        var stats = TestPlan(
            ThreadGroup(2, 10,
                HttpSampler("http://my.service")
                    .Post("{\"name\": \"test\"}", new MediaTypeHeaderValue(MediaTypeNames.Application.Json))
            ),
            //this is just to log details of each request stats
            JtlWriter("jtls")
        ).Run();
        Assert.That(stats.Overall.SampleTimePercentile99, Is.LessThan(TimeSpan.FromSeconds(5)));
    }
}

Java 8+ is required for test plan execution.

More examples can be found in tests

Here is a sample project for reference or for starting new projects from scratch.

Tip 1: When working with multiple samplers in a test plan, specify their names to easily check their respective statistics.

Tip 2: Since JMeter uses log4j2, if you want to control the logging level or output, you can use something similar to the tests included log4j2.xml, using "CopyToOutputDirectory" in the project item so the file is available in dotnet build output directory as well (check [Abstracta.JmeterDsl.Test/Abstracta.JmeterDsl.Tests.csproj]).

Check here for details on some interesting use cases, like running tests at scale in Azure Load Testing, and general usage guides.

Why?

Check more about the motivation and analysis of alternatives here

Support

Join our Discord server to engage with fellow JMeter DSL enthusiasts, ask questions, and share experiences. Visit GitHub Issues or GitHub Discussions for bug reports, feature requests and share ideas.

Abstracta, the main supporter for JMeter DSL development, offers enterprise-level support. Get faster response times, personalized customizations and consulting.

For detailed support information, visit our Support page.

Articles & Talks

Check articles and talks mentioning the Java version here.

Ecosystem

  • Jmeter Java DSL: Java API which is the base of the .Net API.
  • pymeter: Python API based on JMeter Java DSL that allows Python devs to create and run JMeter test plans.

Contributing & Requesting features

Currently, the project covers some of the most used features of JMeter and JMeter Java DSL test, but not everything, as we keep improving it to cover more use cases.

We invest in the development of DSL according to the community's (your) interest, which we evaluate by reviewing GitHub stars' evolution, feature requests, and contributions.

To keep improving the DSL we need you to please create an issue for any particular feature or need that you have.

We also really appreciate pull requests. Check the CONTRIBUTING guide for an explanation of the main library components and how you can extend the library.

jmeter-dotnet-dsl's People

Contributors

rabelenda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

lagroujl

jmeter-dotnet-dsl's Issues

Setting name for HttpSampler is not working

Setting name for HttpSampler("name","url") is not being picked up. All the requests are being recorded under label "Https request". In azure load test , the only sampler name displayed is "Http Request"

Error when trying to execute a simple test using a CSV file and Azure Load Testing

Hello, I have simple load test like this:

[Fact]
public void Ping10Times()
{
    var configuration = new ConfigurationBuilder()
                                   .SetBasePath(Directory.GetCurrentDirectory())
                                   .AddJsonFile("appsettings.json")
                                   .AddUserSecrets<LfraileNetTests>()
                                   .AddEnvironmentVariables()
                                   .Build();
    var stats = TestPlan(
        CsvDataSet("urls.csv")
        .SharedIn(Abstracta.JmeterDsl.Core.Configs.DslCsvDataSet.Sharing.Thread),
        ThreadGroup(1, 10,
        HttpSampler("https://www.lfraile.net/${url}")
        ),
        JtlWriter("jtls")
    )
    .RunIn(
        new AzureEngine(
            tenantId: configuration["LoadTesting:TenantId"],
            clientId: configuration["LoadTesting:ClientId"],
            clientSecret: configuration["LoadTesting:ClientSecret"])
    .TestName("lfloadtestsdemo")
    .SubscriptionId(configuration["LoadTesting:SubscriptionId"])
    .TestResourceName(configuration["LoadTesting:TestResourceName"])
    .ResourceGroupName(configuration["LoadTesting:TestResourceGroup"])
    .Engines(1)
    .TestTimeout(TimeSpan.FromMinutes(5)));
    Assert.True(stats.Overall.Errors.Total == 0);
    Assert.True(stats.Overall.SampleTimePercentile99 < TimeSpan.FromSeconds(5));
}

And the "urls.csv":

url
2019/03/03/environment-variables-and-azure-pipelines/
2019/03/09/opinion-what-and-why-yaml-azure-pipelines/
2019/03/30/some-ideas-on-feature-flags/

And when I try to run it, locally or even for example with GitHub Actions, I always get this error:

[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.5.7+8f2703126a (64-bit .NET 8.0.2)
[xUnit.net 00:00:00.05]   Starting:    PoC.LoadTest.Dsl
[xUnit.net 00:00:02.16]     PoC.LoadTest.Dsl.LfraileNetTests.Ping10Times [FAIL]
[xUnit.net 00:00:02.16]       Abstracta.JmeterDsl.Core.Bridge.JvmException : JVM execution failed. Check stderr and stdout for additional info.
[xUnit.net 00:00:02.16]       Stack Trace:
[xUnit.net 00:00:02.16]            at Abstracta.JmeterDsl.Core.Bridge.BridgeService.WaitJvmProcessExit(Process process)
[xUnit.net 00:00:02.16]            at Abstracta.JmeterDsl.Core.Bridge.BridgeService.RunBridgeCommand(String command, Object testElement, String args)
[xUnit.net 00:00:02.16]            at Abstracta.JmeterDsl.Core.Bridge.BridgeService.RunTestPlanInEngine(DslTestPlan testPlan, IDslJmeterEngine engine)
[xUnit.net 00:00:02.16]            at Abstracta.JmeterDsl.Core.Engines.BaseJmeterEngine`1.Run(DslTestPlan testPlan)
[xUnit.net 00:00:02.16]            at Abstracta.JmeterDsl.Core.DslTestPlan.RunIn(IDslJmeterEngine engine)
[xUnit.net 00:00:02.16]         C:\ws\lfraileorg\jmeter-dsl-net\PoC.LoadTest.Dsl\LfraileNetTests.cs(18,0): at PoC.LoadTest.Dsl.LfraileNetTests.Ping10Times()
[xUnit.net 00:00:02.16]            at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
[xUnit.net 00:00:02.16]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:02.17]   Finished:    PoC.LoadTest.Dsl

If I run the test without Azure Load Testing involved (Just a simple .Run() ) it works perfectly, or if I try tu run the test in Azure Load Testing but without the CSV file.

Is this supported?, Thank you!

`Perc99` lower than `Perc95` and `Perc90`

I encountered a problem, it occasionally happens that Perc99 is smaller than Perc95 and Perc90. How is this possible and why does it happen?

Here is serialized StatsSummary object with threads and iterations info:

{
  "Threads": 100,
  "Iterations": 100,
  "FirstTime": "2023-12-07T17:35:01.284Z",
  "EndTime": "2023-12-07T17:36:21.07Z",
  "Samples": { "Total": 10000, "PerSecond": 125.33527185220464 },
  "SampleTime": {
    "Min": "00:00:00.0430000",
    "Max": "00:00:05.8470000",
    "Mean": "00:00:00.7750000",
    "Median": "00:00:00.8580000",
    "Perc90": "00:00:02.4550000",
    "Perc95": "00:00:02.7660000",
    "Perc99": "00:00:01.6390000"
  },
  "ErrorsCount": 0,
  "SampleTimePercentile99": "00:00:01.6390000",
  "ReceivedBytes": { "Total": 3770000, "PerSecond": 47251.39748828115 },
  "SentBytes": { "Total": 4890000, "PerSecond": 61288.94793572807 }
}

Connect to WebSocket/SignalR

Hello!
I have a project and the base workflow starts when a SignalR method is called.
How can I connect to SignalR or Socket?

Incorporate functionality to verify the expected response.

Hello Team
I have a substantial scenarios where I need to execute multiple POST, GET, and PUT requests. I've observed that in JMeter Java-based, we can assert both the response and JSON response.

Please below sample tests
`

    private const string BaseUrl = "https://your-api.com";


    [Test]
    public void ClientCredentialsFlowLoadTests()
    {

        var stats = TestPlan(
            CsvDataSet("users.csv"),
            HttpCookies().Disable(),
            HttpCache().Disable(),
            ThreadGroup(3, 10,
                HttpSampler("Client Credentials Flow", BaseUrl)
                    .Method(HttpMethod.Post.Method)
                    .ContentType(new System.Net.Http.Headers.MediaTypeHeaderValue(MediaTypeNames.Application.FormUrlEncoded))
                    .Param("grant_type", "client_credentials")
                    .Param("client_id", "${clientId}")
                    .Param("client_secret", "${clientSecret}")
                    .Param("scope", "${scope}")
            ).Children(
                    RegexExtractor("ACCESS_TOKEN", "accessToken=(.*)")
                ),
             ResponseFileSaver(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss").Replace(":", "-") + "-response")
        ).Run();

        Assert.That(stats.Overall.SampleTimePercentile99, Is.LessThan(TimeSpan.FromSeconds(20)));
    }

`

Within my code, I aim to:

  1. Validate the response status.
  2. Retrieve my access token and validate its contents.
  3. Although unrelated to the aforementioned code, I have additional scenarios where I intend to introduce pauses between requests, as illustrated in this resource: https://abstracta.github.io/jmeter-java-dsl/guide/#emulate-user-delays-between-requests

Getting System.InvalidOperationException when running test plan - .Net Framework Library

Code:
var stats = TestPlan(
ThreadGroup(noOfThreads, noOfIterations,
HttpSampler(uri).Method(method)
)
).Run();

System.InvalidOperationException: 'The Process object must have the UseShellExecute property set to false in order to redirect IO streams.'

Message:
Test method RestApiTestProject.RestApiTest.TestApiPerformance threw exception:
System.InvalidOperationException: The Process object must have the UseShellExecute property set to false in order to redirect IO streams.

Stack Trace:
Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
Process.Start()
BridgeService.StartJvmProcess(String jvmArgs)
BridgeService.RunBridgeCommand(String command, Object testElement, String args)
BridgeService.RunTestPlanInEngine(DslTestPlan testPlan, IDslJmeterEngine engine)
BaseJmeterEngine`1.Run(DslTestPlan testPlan)
DslTestPlan.Run()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.