lipanski / mockito

HTTP mocking for Rust!
MIT License
695 stars 59 forks source link

Adds delayed mocks #163

Closed sr-gi closed 1 year ago

sr-gi commented 1 year ago

Adds optional delays to mocks

Fixes #31 #64 #160

sr-gi commented 1 year ago

@lipanski how would you feel about something like this? I think the change is pretty minimal.

I've locally tested it against https://github.com/lipanski/mockito/issues/160#issuecomment-1451841112 and it's being consistent with the delays.

lipanski commented 1 year ago

@sr-gi this feature is a bit too specific for this crate. instead, is there a way to make the with_body_from_request block accept futures? seems like using tokio::time::sleep is the way to go.

sr-gi commented 1 year ago

I'd argue this is actually something pretty useful for an http mock crate. This lets you simulate network delays for instance, which are pretty common and something you may want your code (as in the one using the mock) to account for.

lipanski commented 1 year ago

I don't challenge the use case, but there's already a solution for that (with_body_from_request) which needs some tuning. I'd like to keep the public interface of this crate fairly minimal, whenever possible.

sr-gi commented 1 year ago

I'm not fluent enough with futures to make then change then, sorry.