use html2pdf_api::prelude::*;
use std::time::Duration;
#[tokio::test]
async fn test_pool_creation() {
let result = BrowserPool::builder()
.config(
BrowserPoolConfigBuilder::new()
.max_pool_size(2)
.warmup_count(0) .build()
.unwrap(),
)
.factory(Box::new(
html2pdf_api::factory::mock::MockBrowserFactory::always_fails("Test mode"),
))
.enable_keep_alive(false)
.build();
assert!(result.is_ok(), "Pool creation should succeed");
}
#[tokio::test]
async fn test_pool_stats() {
let pool = BrowserPool::builder()
.config(
BrowserPoolConfigBuilder::new()
.max_pool_size(5)
.warmup_count(0)
.build()
.unwrap(),
)
.factory(Box::new(
html2pdf_api::factory::mock::MockBrowserFactory::always_fails("Test mode"),
))
.enable_keep_alive(false)
.build()
.unwrap();
let stats = pool.stats();
assert_eq!(stats.available, 0);
assert_eq!(stats.active, 0);
}
#[test]
fn test_config_validation() {
let result = BrowserPoolConfigBuilder::new().max_pool_size(0).build();
assert!(result.is_err());
let result = BrowserPoolConfigBuilder::new()
.max_pool_size(3)
.warmup_count(5)
.build();
assert!(result.is_err());
let result = BrowserPoolConfigBuilder::new()
.max_pool_size(5)
.warmup_count(3)
.browser_ttl(Duration::from_secs(3600))
.build();
assert!(result.is_ok());
}
#[tokio::test]
async fn test_shutdown_prevents_operations() {
let mut pool = BrowserPool::builder()
.config(
BrowserPoolConfigBuilder::new()
.max_pool_size(2)
.warmup_count(0)
.build()
.unwrap(),
)
.factory(Box::new(
html2pdf_api::factory::mock::MockBrowserFactory::always_fails("Test mode"),
))
.enable_keep_alive(false)
.build()
.unwrap();
pool.shutdown();
let result = pool.get();
assert!(matches!(result, Err(BrowserPoolError::ShuttingDown)));
}