feat(tests): fix more broken tests, incorrect types

This commit is contained in:
perf3ct 2025-06-22 15:49:14 +00:00
parent 44878acb0e
commit 6afc37ed59
4 changed files with 39 additions and 20 deletions

View File

@ -178,9 +178,11 @@ impl OcrTestClient {
async move {
// Create multipart form
let part = reqwest::multipart::Part::text(content_owned.clone())
.file_name(filename_owned.clone())
.mime_str("text/plain")?;
let form = reqwest::multipart::Form::new()
.text("file", content_owned.clone())
.text("filename", filename_owned);
.part("file", part);
let response = client
.post(&format!("{}/api/documents", base_url))
@ -457,7 +459,7 @@ Every document should retain its own unique signature and number.
Any mixing of content between documents indicates corruption.
Random data: {}
End of Document {}
"#, i, i, timestamp, i*7, i, timestamp * i, i, i);
"#, i, i, i, timestamp, i*7, timestamp * i, i, i);
documents.push((content, format!("doc_{}.txt", i)));
}
@ -486,6 +488,8 @@ End of Document {}
let actual_ocr_text = ocr_result["ocr_text"].as_str().unwrap_or("");
let filename = ocr_result["filename"].as_str().unwrap_or("unknown");
println!("📝 OCR Text for {}: {}", filename, actual_ocr_text);
// Determine which document this should be based on filename
if let Some(doc_num_str) = filename.strip_prefix("doc_").and_then(|s| s.strip_suffix(".txt")) {
if let Ok(doc_num) = doc_num_str.parse::<i32>() {

View File

@ -22,8 +22,6 @@ use readur::{
db_guardrails_simple::DocumentTransactionManager,
};
const TEST_DB_URL: &str = "postgresql://readur_user:readur_password@localhost:5432/readur";
struct OCRPipelineTestHarness {
db: Database,
pool: PgPool,
@ -35,14 +33,18 @@ struct OCRPipelineTestHarness {
impl OCRPipelineTestHarness {
async fn new() -> Result<Self> {
let database_url = std::env::var("TEST_DATABASE_URL")
.or_else(|_| std::env::var("DATABASE_URL"))
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/readur_test".to_string());
// Initialize database connection with higher limits for stress testing
let pool = sqlx::postgres::PgPoolOptions::new()
.max_connections(50) // Increased to support high concurrency tests
.acquire_timeout(std::time::Duration::from_secs(10))
.connect(TEST_DB_URL)
.connect(&database_url)
.await?;
let db = Database::new(TEST_DB_URL).await?;
let db = Database::new(&database_url).await?;
// Initialize services
let file_service = FileService::new("./test_uploads".to_string());
@ -516,9 +518,9 @@ struct DocumentDetails {
file_path: String,
ocr_status: Option<String>,
ocr_text: Option<String>,
ocr_confidence: Option<f64>,
ocr_confidence: Option<f32>,
ocr_word_count: Option<i32>,
ocr_processing_time_ms: Option<i64>,
ocr_processing_time_ms: Option<i32>,
ocr_error: Option<String>,
original_content: Option<String>,
}

View File

@ -41,6 +41,17 @@ impl OCRQueueTestClient {
/// Register and login a test user
async fn register_and_login(&mut self, role: UserRole) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
// First check if server is running
let health_check = self.client
.get(&format!("{}/api/health", get_base_url()))
.send()
.await;
if let Err(e) = health_check {
eprintln!("Health check failed: {}. Is the server running at {}?", e, get_base_url());
return Err(format!("Server not running: {}", e).into());
}
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
@ -64,7 +75,11 @@ impl OCRQueueTestClient {
.await?;
if !register_response.status().is_success() {
return Err(format!("Registration failed: {}", register_response.text().await?).into());
let status = register_response.status();
let text = register_response.text().await?;
eprintln!("Registration failed with status {}: {}", status, text);
eprintln!("Attempted to register user: {} with email: {}", username, email);
return Err(format!("Registration failed: {}", text).into());
}
// Login to get token

View File

@ -16,8 +16,7 @@ use readur::{
AppState,
};
// Test database URL - in real tests you'd use a separate test database
const TEST_DATABASE_URL: &str = "postgres://postgres:password@localhost:5432/readur_test";
// Removed constant - will use environment variables instead
fn create_empty_update_settings() -> UpdateSettings {
UpdateSettings {
@ -74,8 +73,12 @@ fn create_empty_update_settings() -> UpdateSettings {
}
async fn setup_test_app() -> (Router, Arc<AppState>) {
let database_url = std::env::var("TEST_DATABASE_URL")
.or_else(|_| std::env::var("DATABASE_URL"))
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/readur_test".to_string());
let config = Config {
database_url: TEST_DATABASE_URL.to_string(),
database_url: database_url.clone(),
server_address: "127.0.0.1:0".to_string(),
upload_path: "/tmp/test_uploads".to_string(),
watch_folder: "/tmp/test_watch".to_string(),
@ -92,13 +95,8 @@ async fn setup_test_app() -> (Router, Arc<AppState>) {
ocr_timeout_seconds: 300,
};
// Try to connect to test database, fall back to regular database if not available
let db_url = if Database::new(TEST_DATABASE_URL).await.is_ok() {
TEST_DATABASE_URL.to_string()
} else {
std::env::var("DATABASE_URL").unwrap_or_else(|_|
"postgres://postgres:password@localhost:5432/readur".to_string())
};
// Use the environment-based database URL
let db_url = database_url;
let db = Database::new(&db_url).await.expect("Failed to connect to test database");
let queue_service = Arc::new(readur::ocr_queue::OcrQueueService::new(db.clone(), db.pool.clone(), 2));