Git Product home page Git Product logo

Comments (5)

alexchernyavskiy avatar alexchernyavskiy commented on June 15, 2024 2

I join the question. For each request in each iteration, a new request must be created.
My code:

[Test]
public void RegisterTest()
{
    var stats =
    TestPlan(
        ThreadGroup(5, 2,
            HttpSampler("http://localhost/register/")
                .Post(GetRegRequest(), new MediaTypeHeaderValue("application/json")
        ))).Run();
    Assert.That(stats.Overall.SampleTimePercentile99, Is.LessThan(TimeSpan.FromSeconds(2)));

}
//Random random = new Random();
private SecureRandom random = new SecureRandom();
public string GetCardCode()
{
    var getCard = random.Next(0, cardsCount - 1);
    logger.Debug(getCard);
    var cardCode = cards.Skip(getCard).Take(1).FirstOrDefault()?.CardCode;
    logger.Debug(cardCode);
    while (cardCode == null)
    {
        cardCode = cards.Skip(random.Next(0, cardsCount - 1)).Take(1).FirstOrDefault()?.CardCode;
    }
    return cardCode;
}
public string GetRegRequest()
{
    var license = cashes.ToList().ElementAt(random.Next(0, cashCount - 1));
    Guid accessTokenGuid = license.AccessTokenGuid;
    var cardCode = GetCardCode();
    return JsonConvert.SerializeObject(new RegisterRequestDto
    {
        LicenseGuid = license.LicenseGuid,
        AccessTokenGuid = accessTokenGuid,
        CardCode = cardCode,
        CardRegisterDateTime = DateTime.Now,
        RegisterDetailDtos = new List<RegisterDetailDto>
                {
                    new RegisterDetailDto
                    {
                        PositionId="1",
                        ProductCode="12345",
                        Quantity=1,
                        TotalPrice=100
                    }
                }
    });
}

from jmeter-dotnet-dsl.

rabelenda avatar rabelenda commented on June 15, 2024

Hello, thank you for bringing this into attention!

We can easily add the jsr223PreProcessor to the dotnet library with support for specifying code in groovy. Providing support for using c# code and dotnet libraries is not that simple though.

Can you provide an example code of what you would like the DSL to support or how would your think you could express in code what you need?

One alternative for generated and distinct data might also be implementing the csvDataSet element in dotnet library (easy to do as well) so you can generate in dotnet/c# code a CSV with whatever content you may like (and using whatever library you desire) and then just use the proper variables in the HTTP Post request.

In any case, I would like to understand a little better what would be the ideal scenario for your use case and then provide a good approximation to it .

from jmeter-dotnet-dsl.

destructorvad avatar destructorvad commented on June 15, 2024

Tnx for fast reply, this is my code:

.............
using Bogus;

    [Fact]
    public async Task LoadTest()
    {
        // Arrange
        var requestDto = Create_CreateCompanyRequestBogus();
        var request = JsonSerializer.Serialize(requestDto);

        // Act
        var stats = TestPlan(
            ThreadGroup(2, 5,
                HttpSampler("https://tst-api.purpleunity.dev/company-and-contact/api/companies")
                    .Post(request, new MediaTypeHeaderValue(MediaTypeNames.Application.Json))
                    .Header("Authorization", AuthToken)
            ),
            JtlWriter("jtls")
        ).Run();
        stats.Overall.SampleTimePercentile99.Should().BeLessThan(TimeSpan.FromSeconds(5));
    }

    private CreateCompanyRequest Create_CreateCompanyRequestBogus()
    {
        var faker = new Faker<CreateCompanyRequest>()
            .CustomInstantiator(f =>
                new CreateCompanyRequest(
                    IdentityId: Guid.NewGuid().ToString().OrNull(f, 0.2f),
                    Name: f.Company.CompanyName(),
                    VatNumber: f.Random.Replace("??#########").OrNull(f, 0.2f),
                    Iban: f.Random.Replace("??######################").OrNull(f, 0.2f),
                    Bic: f.Finance.Bic().OrNull(f, 0.2f),
                    ChamberOfCommerceNumber : f.Random.Replace("??-???-########").OrNull(f, 0.2f),
                    ExternalId: Guid.NewGuid().ToString().OrNull(f, 0.2f),
                    IsBuyerEvaluated: f.Random.Bool().OrNull(f, 0.2f),
                    Remarks: f.Lorem.Sentences(1).OrNull(f, 0.2f),
                    AddressLine: f.Address.StreetAddress().OrNull(f, 0.2f),
                    Zipcode: f.Address.ZipCode().OrNull(f, 0.2f),
                    City: f.Address.City().OrNull(f, 0.2f),
                    Region: f.Address.State().OrNull(f, 0.2f),
                    CountryCode: f.Address.CountryCode().OrNull(f, 0.2f),
                    Phone: f.Phone.PhoneNumber().OrNull(f, 0.2f),
                    Mobile: f.Phone.PhoneNumber().OrNull(f, 0.2f),
                    Fax: f.Phone.PhoneNumber().OrNull(f, 0.2f),
                    Email: f.Internet.Email().OrNull(f, 0.2f),
                    WebsiteUrl: new Uri(f.Internet.Url()),
                    DefaultContact: null,
                    UseTheSameAddressForPostal: f.Random.Bool().OrNull(f, 0.2f),
                    PostalAddressLine: f.Address.StreetAddress().OrNull(f, 0.2f),
                    PostalZipCode: f.Address.ZipCode().OrNull(f, 0.2f),
                    PostalCity: f.Address.City().OrNull(f, 0.2f),
                    PostalRegion: f.Address.State().OrNull(f, 0.2f),
                    PostalCountry: f.Address.CountryCode().OrNull(f, 0.2f)
                )
            );
        return faker.Generate();
    }

from jmeter-dotnet-dsl.

rabelenda avatar rabelenda commented on June 15, 2024

Great, thank you! The information you two provide is very helpful and we have some ideas that we would like to implement to support these scenarios. It is great to see the community interest in this feature.

If some other have similar interests please let us know!

from jmeter-dotnet-dsl.

rabelenda avatar rabelenda commented on June 15, 2024

We just released 0.4 which includes CsvDataSet and Jsr223PreProcessor.

None of these are optimal solutions for your use cases, but you can use them in the meantime as workarounds or approximations while we come up with some better solution.

Regards

from jmeter-dotnet-dsl.

Related Issues (18)

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.