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:
parent
d0cbd32ad2
commit
2d6a0fdf9c
|
@ -118,12 +118,14 @@ jobs:
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
- uses: Swatinem/rust-cache@v1
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Run ${{ matrix.lua }} tests
|
- name: Run ${{ matrix.lua }} tests
|
||||||
run: |
|
run: |
|
||||||
cargo test --features "${{ matrix.lua }},vendored"
|
cargo test --features "${{ matrix.lua }},vendored"
|
||||||
cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros,parking_lot,unstable"
|
cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros,parking_lot,unstable"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: --cfg mlua_test
|
||||||
- name: Run compile tests (macos lua54)
|
- name: Run compile tests (macos lua54)
|
||||||
if: ${{ matrix.os == 'macos-latest' && matrix.lua == 'lua54' }}
|
if: ${{ matrix.os == 'macos-latest' && matrix.lua == 'lua54' }}
|
||||||
run: |
|
run: |
|
||||||
|
@ -149,12 +151,13 @@ jobs:
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
- uses: Swatinem/rust-cache@v1
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Run ${{ matrix.lua }} tests with address sanitizer
|
- name: Run ${{ matrix.lua }} tests with address sanitizer
|
||||||
run: |
|
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
|
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
|
shell: bash
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: --cfg mlua_test -Z sanitizer=address
|
||||||
|
|
||||||
test_modules:
|
test_modules:
|
||||||
name: Test modules
|
name: Test modules
|
||||||
|
@ -176,7 +179,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
- uses: Swatinem/rust-cache@v1
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Run ${{ matrix.lua }} module tests
|
- name: Run ${{ matrix.lua }} module tests
|
||||||
run: |
|
run: |
|
||||||
(cd tests/module && cargo build --release --features "${{ matrix.lua }}")
|
(cd tests/module && cargo build --release --features "${{ matrix.lua }}")
|
||||||
|
|
|
@ -247,6 +247,8 @@ impl Drop for LuaInner {
|
||||||
{
|
{
|
||||||
(*ffi::lua_callbacks(self.state())).userdata = ptr::null_mut();
|
(*ffi::lua_callbacks(self.state())).userdata = ptr::null_mut();
|
||||||
}
|
}
|
||||||
|
// This is an internal assertion used in integration tests
|
||||||
|
#[cfg(mlua_test)]
|
||||||
mlua_debug_assert!(
|
mlua_debug_assert!(
|
||||||
ffi::lua_gettop(extra.ref_thread) == extra.ref_stack_top
|
ffi::lua_gettop(extra.ref_thread) == extra.ref_stack_top
|
||||||
&& extra.ref_stack_top as usize == extra.ref_free.len(),
|
&& extra.ref_stack_top as usize == extra.ref_free.len(),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use futures_util::stream::TryStreamExt;
|
||||||
|
|
||||||
use mlua::{
|
use mlua::{
|
||||||
AnyUserDataExt, Error, Function, Lua, LuaOptions, Result, StdLib, Table, TableExt, UserData,
|
AnyUserDataExt, Error, Function, Lua, LuaOptions, Result, StdLib, Table, TableExt, UserData,
|
||||||
UserDataMethods,
|
UserDataMethods, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -270,6 +270,28 @@ async fn test_async_thread() -> Result<()> {
|
||||||
Ok(())
|
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]
|
#[tokio::test]
|
||||||
async fn test_async_table() -> Result<()> {
|
async fn test_async_table() -> Result<()> {
|
||||||
let options = LuaOptions::new().thread_pool_size(4);
|
let options = LuaOptions::new().thread_pool_size(4);
|
||||||
|
|
Loading…
Reference in New Issue