-
Notifications
You must be signed in to change notification settings - Fork 247
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
refactor(rumqttc): make AsyncClient/Eventloop mockable #885
Conversation
Signed-off-by: Marc Bodmer <[email protected]>
Signed-off-by: Marc Bodmer <[email protected]>
Signed-off-by: Marc Bodmer <[email protected]>
Signed-off-by: Marc Bodmer <[email protected]>
Any chance this is going to be accepted? |
Great work. I'm also very interested in getting this merged as it would be incredibly helpful for our testing process. Looking forward to seeing this merged soon |
Hey @mbodmer , thanks for the PR. As per the example in PR, mock eventloop is just an wrapper and uses Please feel free to lmk if I'm missing something, thank you for understanding :) |
Thanks so much for your feedback @swanandx I am not sure I completely understand your suggestion. Also the example might not completely capture my situation. My client code is something like: pub struct MqttClientService<S> {
pub(crate) client: AsyncClient,
pub(crate) eventloop: EventLoop,
pub(crate) inner: S,
} Here I cannot make the |
let me elaborate: for mock eventlloop struct MockEventloop {
rx: Receiver<Request>,
}
// impl MockEventloop as you wish
// To create client and eventloop you can do something like:
let (tx, rx) = flume::unbounded();
let client = AsyncClient::from_senders(tx);
let eventloop = MockEventloop { rx }; Coming to your code, you want to have Eventloop such that both rumqttc's Eventloop and your mock eventloop can integrate with your MqttClientService right? For that, you can define and implement that trait inside your code as well right? for Eventloop you can just call it's poll internally, and for Mockeventloop you can do as you need. pseudocode: impl Pollable for EventLoop {
fn poll(..) {
self.poll().await
}
} Otherwise, you can have MockMqttClient which holds the rx ( instead of eventloop ) which you can use for testing. |
You are right, this might work. I will try this and report back. Thanks for maintaining rumqtt! |
cool! feel free to reopen / comment if required, thanks :) |
I have the need to mock the interface to the rumqttc client for testing/benching purposes.
There was no evident way I could achieve this other than introducing a new trait
PollableEventLoop
defining the poll interface on theEventLoop
.Now it is possible to reuse the
AsyncClient
and mock theEventLoop
.I have also added a mocked version of the
asyncpubsub
example.This change will make it mandatory to
use rumqttc::PollableEventLoop
, that is why I mark this as a breaking change.Type of change
Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist:
cargo fmt
CHANGELOG.md
if it's relevant to the users of the library. If it's not relevant mention why.