Check for reference leak detection only in mlua integratin tests.

This is not necessary an error and should not be enforced by default.
Fixes #268.
This commit is contained in:
Alex Orlenko 2023-04-23 10:03:16 +01:00
parent d0cbd32ad2
commit 2d6a0fdf9c
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
3 changed files with 32 additions and 5 deletions

View File

@ -118,12 +118,14 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- name: Run ${{ matrix.lua }} tests
run: |
cargo test --features "${{ matrix.lua }},vendored"
cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros,parking_lot,unstable"
shell: bash
env:
RUSTFLAGS: --cfg mlua_test
- name: Run compile tests (macos lua54)
if: ${{ matrix.os == 'macos-latest' && matrix.lua == 'lua54' }}
run: |
@ -149,12 +151,13 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- name: Run ${{ matrix.lua }} tests with address sanitizer
run: |
RUSTFLAGS="-Z sanitizer=address" \
cargo test --tests --features "${{ matrix.lua }},vendored,async,send,serialize,macros,parking_lot,unstable" --target x86_64-unknown-linux-gnu -- --skip test_too_many_recursions
shell: bash
env:
RUSTFLAGS: --cfg mlua_test -Z sanitizer=address
test_modules:
name: Test modules
@ -176,7 +179,7 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- name: Run ${{ matrix.lua }} module tests
run: |
(cd tests/module && cargo build --release --features "${{ matrix.lua }}")

View File

@ -247,6 +247,8 @@ impl Drop for LuaInner {
{
(*ffi::lua_callbacks(self.state())).userdata = ptr::null_mut();
}
// This is an internal assertion used in integration tests
#[cfg(mlua_test)]
mlua_debug_assert!(
ffi::lua_gettop(extra.ref_thread) == extra.ref_stack_top
&& extra.ref_stack_top as usize == extra.ref_free.len(),

View File

@ -9,7 +9,7 @@ use futures_util::stream::TryStreamExt;
use mlua::{
AnyUserDataExt, Error, Function, Lua, LuaOptions, Result, StdLib, Table, TableExt, UserData,
UserDataMethods,
UserDataMethods, Value,
};
#[tokio::test]
@ -270,6 +270,28 @@ async fn test_async_thread() -> Result<()> {
Ok(())
}
#[test]
fn test_async_thread_leak() -> Result<()> {
let lua = Lua::new();
let f = lua.create_async_function(move |_lua, v: Value| async move {
tokio::task::yield_now().await;
drop(v);
Ok(())
})?;
let thread = lua.create_thread(f)?;
// After first resume, `v: Value` is captured in the coroutine
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(())
}
#[tokio::test]
async fn test_async_table() -> Result<()> {
let options = LuaOptions::new().thread_pool_size(4);