WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Request matching WithProbability strange behaviour

Open mihailtrifonovio opened this issue 1 year ago • 4 comments

Based on article for "Chaos Engineering with Fault Injections" I've added following code:

var server = StandAloneApp.Start(new WireMockServerSettings {  Port = 8888 } );

        server
          .Given(Request.Create().WithPath("/test").UsingGet())
          .WithProbability(0.5)
          .RespondWith(Response.Create()
              .WithStatusCode(200)
              .WithBody(@"Success")
            );

        server
          .Given(Request.Create().WithPath("/test").UsingGet())
          .RespondWith(Response.Create()
              .WithStatusCode(500)
              .WithBody(@"Internal Server error")
          );

My expectation is that around 50% of the time there will be faults. However it is 100% of the time. If second matching is removed then there is some distribution between 200 and 404(no matching found), but is not 1:1 and more like 5:1 in favor of 404.

Is there something I'm missing?

mihailtrifonovio avatar Jun 20 '24 13:06 mihailtrifonovio

@mihailtrifonovio Can you provide a example project?

StefH avatar Oct 16 '24 08:10 StefH

@mihailtrifonovio Can you provide a example project?

StefH avatar Dec 07 '24 14:12 StefH

@mihailtrifonovio Can you provide a example project?

StefH avatar Jan 11 '25 07:01 StefH

Did this ever get sorted? I'm using the aspire integration (1.7.4 & 1.8.0-prview-01).

var apiServiceUsedForDocs = builder
    .AddWireMock("apiservice1", WireMockServerArguments.DefaultPort)
    .WithApiMappingBuilder(adminApiBuilder =>
    {
        adminApiBuilder.Given(b => b
            .WithRequest(request => request
                .UsingGet()
                .WithPath("/test")
            )
            .WithProbability(0.7)
            .WithResponse(response => response
                .WithStatusCode(200)
                .WithBody("{ \"message\": \"Success\" }")
                .WithHeaders(new Dictionary<string, object>()
                {
                    {"Content-Type", "application/json"}
                })
            )
        );

        adminApiBuilder.Given(b => b
            .WithRequest(request => request
                .UsingGet()
                .WithPath("/test")
            )
            .WithResponse(response => response

                .WithStatusCode(500)
                .WithBody("{ \"message\": \"500\" }")
                .WithHeaders(new Dictionary<string, object>()
                {
                    {"Content-Type", "application/json"}
                }
                )
            )
        );

        return adminApiBuilder.BuildAndPostAsync();
    });

It's just returning the failure (500) response.

TheRubble avatar Apr 16 '25 20:04 TheRubble