Attempt to deal with task/memory leaks
All checks were successful
Build library & run tests / docs (push) Successful in 2m20s
Build library & run tests / build (unix) (push) Successful in 2m23s
Build library & run tests / build (tcp) (push) Successful in 2m27s

This commit is contained in:
2024-06-26 11:16:20 +02:00
parent a1e10f93ce
commit d47f62cdbb
7 changed files with 774 additions and 41 deletions

View File

@@ -24,9 +24,10 @@ use tokio::sync::{
Notify,
};
static INIT: Once = Once::new();
static LOG_INIT: Once = Once::new();
static CONSOLE_INIT: Once = Once::new();
pub fn init_logger() {
INIT.call_once(|| {
LOG_INIT.call_once(|| {
let env = Env::default()
.filter_or("RUST_LOG", "info")
.write_style_or("LOG_STYLE", "always");
@@ -34,6 +35,11 @@ pub fn init_logger() {
Builder::from_env(env).format_timestamp_nanos().init();
});
}
pub fn init_console() {
CONSOLE_INIT.call_once(|| {
console_subscriber::init();
});
}
#[derive(Protocol)]
enum TestProtocol {
@@ -46,6 +52,7 @@ enum TestProtocol {
#[tokio::test]
async fn client() {
init_logger();
init_console();
let (qtx, qrx) = mpsc::channel(16);
let (atx, arx) = mpsc::channel(16);
let ready_notify = Arc::new(Notify::new());
@@ -110,6 +117,7 @@ async fn server_loop(
#[tokio::test]
async fn heavy_async() {
init_logger();
init_console();
let (qtx, qrx) = mpsc::channel(16);
let (atx, arx) = mpsc::channel(16);
let ready_notify = Arc::new(Notify::new());

View File

@@ -18,10 +18,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
use eagle::Protocol;
use env_logger::{Builder, Env};
use std::sync::Once;
use tokio::net::TcpStream;
static INIT: Once = Once::new();
static LOG_INIT: Once = Once::new();
static CONSOLE_INIT: Once = Once::new();
pub fn init_logger() {
INIT.call_once(|| {
LOG_INIT.call_once(|| {
let env = Env::default()
.filter_or("RUST_LOG", "info")
.write_style_or("LOG_STYLE", "always");
@@ -29,6 +31,11 @@ pub fn init_logger() {
Builder::from_env(env).format_timestamp_nanos().init();
});
}
pub fn init_console() {
CONSOLE_INIT.call_once(|| {
console_subscriber::init();
});
}
#[derive(Protocol)]
enum TestProtocol {
@@ -65,6 +72,7 @@ impl Drop for Cleanup {
#[tokio::test]
async fn e2e() {
init_logger();
init_console();
#[cfg(feature = "unix")]
let address = format!("/tmp/eagle-test-{}.sock", rand::random::<u64>());
#[cfg(feature = "unix")]
@@ -73,7 +81,7 @@ async fn e2e() {
};
#[cfg(feature = "tcp")]
let address = format!("127.0.0.1:{}", 10000 + rand::random::<u64>() % 1000);
let server = TestProtocolServer::bind(TrivialServer, address.clone()).await;
let _server = TestProtocolServer::bind(TrivialServer, address.clone()).await;
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await; // Wait for the server to start
let client = TestProtocolClient::connect(address).await.unwrap();
assert_eq!(client.addition(2, 5).await.unwrap(), 7);
@@ -89,5 +97,4 @@ async fn e2e() {
"The number is 42"
);
client.void().await.unwrap();
server.close().await;
}