Skip to content

Commit 00dc279

Browse files
committed
change init_sync according to review suggestion and add comment about usage limitation
Signed-off-by: Otto Westerlund <westerlundotto@gmail.com>
1 parent b5b389c commit 00dc279

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/common/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,18 @@ pub async fn init() -> Result<()> {
7474
Ok(())
7575
}
7676

77+
/// Initialize the test environment synchronously.
78+
///
79+
/// This function creates its own tokio runtime and must be called from
80+
/// synchronous code only (e.g., at the start of a `#[test]` function).
81+
///
82+
/// **Do not call this from inside an async function or tokio runtime** -
83+
/// it will panic. If you're already in an async context, use `init()` directly.
7784
pub fn init_sync() -> Result<()> {
78-
if let Ok(handle) = tokio::runtime::Handle::try_current() {
79-
handle.block_on(init())
80-
} else {
81-
tokio::runtime::Runtime::new()?.block_on(init())
82-
}
85+
tokio::runtime::Builder::new_current_thread()
86+
.enable_all()
87+
.build()?
88+
.block_on(init())
8389
}
8490

8591
async fn ensure_region_split(

0 commit comments

Comments
 (0)