question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stay in Current State for specified number of requests

See original GitHub issue

Hey guy,s I need to write mocks such that a request keeps faulting for a given number of time before it can succeed. I know that I can use Scenarios for this.

But there’s a problem. Let’s suppose I want to fault my request 2 times before succeeding on 3rd attempt. So I have to write three mocks where flow would be like this:

-- 1st Mock:
    -- Set next state to "fail"
    -- Fail request

-- 2nd Mock:
    -- When current state is "fail"
    -- Set next state to "pass"
    -- Fail request

-- 3rd Mock:
    -- When current state is "pass"
    -- Pass request

We can see that first 2 states are just doing same thing. So my question is this: Is it possible to build a mock which stay in its current state for a given number of time, before switching to next one. So my mocks would be like below:

-- 1st Mock:
    -- Set next state to "pass" ONLY after 2 requests
    -- Fail request

-- 2nd Mock:
    -- When current state is "pass"
    -- Pass request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
StefHcommented, Aug 1, 2020

@shoaibshakeel381 Can you try preview version WireMock.Net.1.2.16-ci-13650.nupkg from MyGet ? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

1reaction
StefHcommented, Jul 30, 2020

@shoaibshakeel381

Probably the interface can look like:

var server = WireMockServer.Start();

server
                .Given(Request.Create().WithPath(path).UsingGet())
                .InScenario("S")
                .WillSetStateTo("bar")
                .WhenMatchingCountEquals(2)
                .RespondWith(Response.Create().WithBody("Scenario S, Setting State bar"));

server
                .Given(Request.Create().WithPath(path).UsingGet())
                .InScenario("S")
                .WhenStateIs("bar")
                .RespondWith(Response.Create().WithBody("Scenario S, State bar"));

or

var server = WireMockServer.Start();

server
                .Given(Request.Create().WithPath(path).UsingGet())
                .InScenario("S")
                .WillSetStateTo("bar", 2) // 2 = matching count
                .RespondWith(Response.Create().WithBody("Scenario S, Setting State bar"));

server
                .Given(Request.Create().WithPath(path).UsingGet())
                .InScenario("S")
                .WhenStateIs("bar")
                .RespondWith(Response.Create().WithBody("Scenario S, State bar"));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Quotas - AWS Step Functions - AWS Documentation
AWS Step Functions places quotas on the sizes of certain state machine parameters, such as the number of API actions during a certain...
Read more >
Invoke-WebRequest - PowerShell
The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of...
Read more >
HTTP/1.1: Status Code Definitions
10.2 Successful 2xx. This class of status code indicates that the client's request was successfully received, understood, and accepted.
Read more >
HTTP Request Methods – Get vs Put vs Post Explained ...
In this article, we'll be discussing the get, put, and post HTTP methods. You'll learn what each HTTP method is used for as...
Read more >
How to Fix 429 Too Many Requests Error
The HTTP 429 error is returned when a user has sent too many requests within a short period of time. The 429 status...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found