Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper for delay in milliseconds #312

Closed
wants to merge 0 commits into from

Conversation

prashanth-92
Copy link
Contributor

#232 Attempts to provide a helper for adding a delay in milliseconds. The test shows a way to use the method.

@ctimmerm
Copy link
Owner

ctimmerm commented Sep 7, 2021

Hi @prashanth-92! Thanks for your PR, but unfortunately your change doesn't actually introduce per-request delays. The added method instead sets the delay for all requests, so for example:

mock.delayInMs(200).onGet("/foo").reply(200);
mock.delayInMs(0).onGet("/bar").reply(200);

will cause no delay when a request to /foo is made.

@prashanth-92
Copy link
Contributor Author

prashanth-92 commented Sep 7, 2021

Hey @ctimmerm, yes my solution is setting the delay in the MockAdapter directly. So it will work for one endpoint but if you set it again, it will get overridden

Just to see if I get this right, if we need to add it at an endpoint level, then we might need to introduce a state in the handlers per verb and then use delay it with a promise approach you mentioned in one of the comments.

@prashanth-92
Copy link
Contributor Author

@ctimmerm I have a revised approach with delay per request. Can you please review it?

@prashanth-92
Copy link
Contributor Author

Ping @ctimmerm If you have some time, please review this pull request

@prashanth-92
Copy link
Contributor Author

Hey @ctimmerm when you have time, please review this pull request. I would really appreciate it.

if(handler.length === 8){
delayPerRequest = handler[7];
}
return adapter.delayResponse + delayPerRequest
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding it to the global delay, I think it would be more intuitive if it overrode the global delay instead.

Copy link
Contributor Author

@prashanth-92 prashanth-92 Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually makes sense, I have adjusted, please take a look.

@prashanth-92
Copy link
Contributor Author

Please re-review @ctimmerm

@prashanth-92
Copy link
Contributor Author

Please re review.

@prashanth-92
Copy link
Contributor Author

@ctimmerm please review.

@prashanth-92
Copy link
Contributor Author

@ctimmerm Can you please re review?

src/index.js Outdated
return _this;
}

function withDelayInMs(delay){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming inconstency: above method replyWithDelay does not have InMs suffix.

Rename to withDelay?

@jshall
Copy link

jshall commented Feb 3, 2022

I would also be interested to have withDelay() accept a function. This would allow me to create a function that generates a random delay in a specific range.

@prashanth-92
Copy link
Contributor Author

I would also be interested to have withDelay() accept a function. This would allow me to create a function that generates a random delay in a specific range.

The idea behind this pull request is to give a helper for introducing a delay time alone. Your new feature request can be addressed in another pull request. Feel free to open one.

@phiter
Copy link

phiter commented Jan 31, 2023

Hey guys, is this getting merged or nah? I just found a use case where I need a delay for a specific request.

@prashanth-92
Copy link
Contributor Author

@ctimmerm If there are no concerns, can we merge this PR? I think it will be useful.

@marcbachmann
Copy link
Collaborator

hmm, a force push merged this accidentally and can't reopen. I'll merge this manually

@marcbachmann
Copy link
Collaborator

marcbachmann commented Sep 11, 2023

hah. reopen button shows up again.

edit: nope. didn't work

@marcbachmann
Copy link
Collaborator

Released as v1.22.0

@jfstephe
Copy link

marcbachmann, prashanth-92 - I'm a bit late to the party but there's no documentation and I think the typescript definitions are missing...

@jfstephe
Copy link

Also IMHO the API for this is now unintuitive (it looked like @ctimmerm had a good suggestion). Why the change to make this return the reply function rather than the request handler?

@Glideh
Copy link

Glideh commented Oct 17, 2023

Interested about that too.
Need a doc & types up to date plz.

@seriouslag
Copy link

Interested about that too. Need a doc & types up to date plz.

I opened a PR to add types to replyWithDelay
#383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants