Skip to content

Commit 3947017

Browse files
committed
Switch to current thread runtime
This switches to use the current thread runtime in tests, to avoid spawning additional threads. An interesting side effect of this change alone is that the tests hang waiting for the joinhandle of the `MysqlIntermediary::run_on_tcp` thread, which never returns. This seems to be because the runtime hasn't finished cleaning up by the time `block_on` exits, so the tcp connection remains open. Calling `rt.shutdown_background` immediately after `rt.block_on` fixes this.
1 parent 073d548 commit 3947017

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests/async.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ where
104104
MysqlIntermediary::run_on_tcp(self, s)
105105
});
106106

107-
let rt = tokio::runtime::Runtime::new().unwrap();
107+
let rt = tokio::runtime::Builder::new_current_thread()
108+
.enable_all()
109+
.build()
110+
.unwrap();
108111
rt.block_on(async {
109112
let conn = mysql_async::Conn::new(
110113
Opts::from_url(&format!("mysql://127.0.0.1:{}", port)).unwrap(),
@@ -114,6 +117,7 @@ where
114117
c(conn).await
115118
})
116119
.unwrap();
120+
rt.shutdown_background();
117121

118122
jh.join().unwrap().unwrap();
119123
}

0 commit comments

Comments
 (0)