Replies: 6 comments
-
You guessed correctly that |
Beta Was this translation helpful? Give feedback.
-
@asomers Thanks for the suggestion but I'm afraid that doesn't work either. This is what I've tried: #[test]
fn should_fail_count() {
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
rt.block_on(async {
let mut mock1 = MockMyStruct::new();
let mut mock2 = MockMyStruct::new();
mock2.expect_foo().times(2).returning(|| {});
mock1.expect_clone().return_once(move || mock2);
let consumer = MyOtherStruct::new(mock1);
consumer.make_it_disappear().await;
});
} The test is still passing |
Beta Was this translation helpful? Give feedback.
-
Try running your test with |
Beta Was this translation helpful? Give feedback.
-
Sorry for the necromancy: @cortopy, were you able to solve this? I am having the exact same problem |
Beta Was this translation helpful? Give feedback.
-
Same for me :-( |
Beta Was this translation helpful? Give feedback.
-
I've run into the same issue, and I fixed it by joining the In my case, the Tokio task is spawned in |
Beta Was this translation helpful? Give feedback.
-
It seems that when a mock is moved into an async task, expectations may be ignored.
If we have:
And I write this test:
The mock acts like it indeed dissapeared, as
.times(2)
is totally ignored and the test passes even thoughfoo
was called only onceTrying more things I've noticed that if I have instead:
the expectations are checked and the test fails.
I'm assuming that since the task was never awaited, expectations weren't checked. However, the test finishes ok and so the mock should be dropped at some point. Could this not be checked?
Beta Was this translation helpful? Give feedback.
All reactions