LukeMathWalker / wiremock-rs

HTTP mocking to test Rust applications.
Apache License 2.0
607 stars 69 forks source link

Add MockGuard::is_satisfied #116

Closed ThomWright closed 8 months ago

ThomWright commented 1 year ago

The intention here is to make it easier to handle situations where we don't know when to expect the mock to be called.

For example, when testing async message consumers, the tests might publish a message and need to assert that the message consumer sent an HTTP request.

Unlike request/response-style HTTP endpoints, the tests don't know when the message consumer has finished processing.

In these cases, one technique is to wait for an expected condition to become true, e.g. a mock being called!

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

LukeMathWalker commented 1 year ago

Happy to add it, just left a couple of minor comments πŸ‘πŸ»

ThomWright commented 1 year ago

Thanks, I pushed some fixes.

@conradludgate has a better idea (of course!): a method which waits until the expectations are satisfied without polling, with presumably a configurable timeout.

I'll let him do the hard work on that one πŸ˜‰

LukeMathWalker commented 1 year ago

Talk to me about it @conradludgate πŸ‘€

conradludgate commented 1 year ago

Haha very well, I started a branch locally. Let me push it up with what I have currently.

Basically, the idea was the lean into the "poll" approach of an is_satisfied API and make it a Future/async setup instead. So the MockServer will trigger a waker and wake up all those who are waiting for a satisfied event

LukeMathWalker commented 1 year ago

I think they could live next to each other, but it'd be nice to offer bothβ€”I left some comments on the other PR @conradludgate

LukeMathWalker commented 8 months ago

Closing this since we merged Conrad's work.