#![cfg(not(target_arch = "wasm32"))]
use absurder_sql::storage::{BLOCK_SIZE, BlockStorage};
use serial_test::serial;
use tempfile::TempDir;
#[path = "common/mod.rs"]
mod common;
#[tokio::test(flavor = "current_thread")]
#[serial]
async fn test_auto_sync_clears_dirty_blocks_on_next_op() {
let tmp = TempDir::new().expect("tempdir");
common::set_var("ABSURDERSQL_FS_BASE", tmp.path());
let mut storage = BlockStorage::new_with_capacity("test_auto_sync", 8)
.await
.expect("create storage");
storage.enable_auto_sync(50);
let data = vec![1u8; BLOCK_SIZE];
storage.write_block(10, data).await.expect("write block 10");
assert_eq!(storage.get_dirty_count(), 1);
tokio::time::sleep(std::time::Duration::from_millis(120)).await;
let _ = storage
.read_block(10)
.await
.expect("read triggers auto sync");
assert_eq!(storage.get_dirty_count(), 0);
}