mod common;
use std::time::Duration;
use common::spawn_full_server;
use tokio_test::assert_ok;
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[tokio::test]
async fn test_heap_allocation() -> anyhow::Result<()> {
let _profiler = dhat::Profiler::builder().testing().build();
common::init();
let (addr, server_handle, shutdown) = assert_ok!(spawn_full_server().await);
let stats = dhat::HeapStats::get();
dbg!(stats);
let clients = common::generate_connections(1, addr, 5).await;
let stats = dhat::HeapStats::get();
dbg!(stats);
for (i, client) in clients.into_iter().enumerate() {
let result = assert_ok!(client.await);
assert_eq!(result, i);
}
tokio::time::sleep(Duration::from_secs(1)).await;
let stats = dhat::HeapStats::get();
dbg!(stats);
tokio::time::sleep(Duration::from_secs(2)).await;
shutdown.cancel();
let server_result = assert_ok!(server_handle.await);
assert_ok!(server_result);
Ok(())
}