summaryrefslogtreecommitdiffstats
path: root/tokio-test/src
diff options
context:
space:
mode:
Diffstat (limited to 'tokio-test/src')
-rw-r--r--tokio-test/src/io.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tokio-test/src/io.rs b/tokio-test/src/io.rs
index f1ce77aa..ac70a06f 100644
--- a/tokio-test/src/io.rs
+++ b/tokio-test/src/io.rs
@@ -458,6 +458,21 @@ impl AsyncWrite for Mock {
}
}
+/// Ensures that Mock isn't dropped with data "inside".
+impl Drop for Mock {
+ fn drop(&mut self) {
+ // Avoid double panicking, since makes debugging much harder.
+ if std::thread::panicking() {
+ return;
+ }
+
+ self.inner.actions.iter().for_each(|a| match a {
+ Action::Read(data) => assert!(data.is_empty(), "There is still data left to read."),
+ Action::Write(data) => assert!(data.is_empty(), "There is still data left to write."),
+ _ => (),
+ })
+ }
+}
/*
/// Returns `true` if called from the context of a futures-rs Task
fn is_task_ctx() -> bool {