From 4daa7de9978d7dfe43c40e8081a94aaaacf48645 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 26 Apr 2023 15:34:15 +0100 Subject: Various improvements for owned types, including: - tests - shortcuts for `OwnedFunction` and `OwnedAnyUserData` --- tests/async.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'tests/async.rs') diff --git a/tests/async.rs b/tests/async.rs index 9ba06da..bc1448f 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -271,7 +271,7 @@ async fn test_async_thread() -> Result<()> { } #[test] -fn test_async_thread_leak() -> Result<()> { +fn test_async_thread_capture() -> Result<()> { let lua = Lua::new(); let f = lua.create_async_function(move |_lua, v: Value| async move { @@ -285,10 +285,6 @@ fn test_async_thread_leak() -> Result<()> { thread.resume::<_, ()>("abc").unwrap(); drop(thread); - // Without running garbage collection, the captured `v` would trigger "reference leak detected" error - // with `cfg(mlua_test)` - lua.gc_collect()?; - Ok(()) } @@ -488,3 +484,21 @@ async fn test_async_thread_error() -> Result<()> { Ok(()) } + +#[cfg(all(feature = "unstable", not(feature = "send")))] +#[tokio::test] +async fn test_owned_async_call() -> Result<()> { + let lua = Lua::new(); + + let hello = lua + .create_async_function(|_, name: String| async move { + Delay::new(Duration::from_millis(10)).await; + Ok(format!("hello, {}!", name)) + })? + .into_owned(); + drop(lua); + + assert_eq!(hello.call_async::<_, String>("alex").await?, "hello, alex!"); + + Ok(()) +} -- cgit v1.2.3