test: add CI, RingBuffer tests, core proptest, RAII lua fixtures

This commit is contained in:
2026-08-17 21:19:33 +08:00
parent 81c0ce13c4
commit 5f5477d658
12 changed files with 450 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::Once;
use std::time::Duration;
use std::{fs, path::PathBuf};
use mlua::Lua;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -17,14 +18,30 @@ fn init_tracing() {
});
}
fn write_temp_lua(name: &str, script: &str) -> PathBuf {
let nonce = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos();
let path = std::env::temp_dir().join(format!("pipeview_{name}_{nonce}.lua"));
fs::write(&path, script).unwrap();
path
struct TempScript {
path: PathBuf,
_guard: tempfile::TempPath,
}
impl TempScript {
fn new(name: &str, script: &str) -> Self {
let mut file = tempfile::Builder::new()
.prefix(&format!("pipeview_{name}_"))
.suffix(".lua")
.tempfile()
.unwrap();
file.write_all(script.as_bytes()).unwrap();
let path = file.path().to_path_buf();
let guard = file.into_temp_path();
Self {
path,
_guard: guard,
}
}
fn path(&self) -> &Path {
&self.path
}
}
fn text_pipeline_lua() -> &'static str {
@@ -208,7 +225,7 @@ async fn lua_session_custom_lua_pipeline() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap().to_string();
let framer_path = write_temp_lua(
let framer_script = TempScript::new(
"custom_framer",
r#"
local buffer = ""
@@ -239,7 +256,7 @@ async fn lua_session_custom_lua_pipeline() {
}
"#,
);
let decoder_path = write_temp_lua(
let decoder_script = TempScript::new(
"custom_decoder",
r#"
return {
@@ -287,14 +304,12 @@ async fn lua_session_custom_lua_pipeline() {
sess:close()
"#,
addr,
framer_path.display(),
decoder_path.display()
framer_script.path().display(),
decoder_script.path().display()
);
lua.load(&script).exec_async().await.unwrap();
server.await.unwrap();
fs::remove_file(framer_path).unwrap();
fs::remove_file(decoder_path).unwrap();
}
// ── session:on_data callback ─────────────────────────────────────