178 lines
5.2 KiB
Rust
178 lines
5.2 KiB
Rust
//! TDD tests for engine fixes
|
|
//! These tests define expected behavior for engine execution and metrics recording
|
|
|
|
use rtx_etl::{
|
|
Result,
|
|
dag::{Task, TaskType},
|
|
engine::EtlEngine,
|
|
monitoring::EtlMetrics,
|
|
quality::QualityMonitor,
|
|
state::StateManager,
|
|
};
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
#[tokio::test]
|
|
async fn test_task_has_config_field() {
|
|
// Test that Task struct has config field for accessing task configuration
|
|
let mut task = Task::new("test_task".to_string(), TaskType::Extract);
|
|
|
|
// Should be able to access config field
|
|
task.config
|
|
.insert("source".to_string(), serde_json::json!("test_source"));
|
|
task.config
|
|
.insert("batch_size".to_string(), serde_json::json!(100));
|
|
|
|
// Config should be accessible
|
|
let source = task.config.get("source").unwrap();
|
|
assert_eq!(source, &serde_json::json!("test_source"));
|
|
|
|
let batch_size = task.config.get("batch_size").unwrap();
|
|
assert_eq!(batch_size, &serde_json::json!(100));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_metrics_record_task_execution_signature() {
|
|
// Test that record_task_execution method accepts 4 parameters
|
|
let metrics = EtlMetrics::new();
|
|
|
|
let task_id = "test_task";
|
|
let task_type = TaskType::Extract;
|
|
let execution_time = Duration::from_millis(500);
|
|
let success = true;
|
|
|
|
// Should accept 4 parameters as currently implemented
|
|
metrics
|
|
.record_task_execution(task_id, &task_type, execution_time, success)
|
|
.await;
|
|
|
|
// Should be able to get task stats
|
|
let stats = metrics.get_task_stats(task_id).await;
|
|
assert!(stats.is_some());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_state_manager_update_task_state() {
|
|
// Test that StateManager has update_task_state method
|
|
use rtx_etl::state::StateConfig;
|
|
let state_manager = StateManager::new(StateConfig::default()).await.unwrap();
|
|
|
|
let task_id = "test_task";
|
|
let state_value = "completed_at_123456789";
|
|
|
|
// Should be able to update task state
|
|
state_manager
|
|
.update_task_state(task_id, state_value)
|
|
.await
|
|
.unwrap();
|
|
|
|
// Should be able to retrieve the state
|
|
let retrieved_state = state_manager
|
|
.get_state(&format!("task_state_{}", task_id))
|
|
.await
|
|
.unwrap();
|
|
assert!(retrieved_state.is_some());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_quality_monitor_record_score() {
|
|
// Test that QualityMonitor has record_quality_score method
|
|
let quality_monitor = QualityMonitor::new().await.unwrap();
|
|
|
|
let task_id = "test_task";
|
|
let quality_score = 0.95;
|
|
|
|
// Should be able to record quality score
|
|
quality_monitor
|
|
.record_quality_score(task_id, quality_score)
|
|
.await
|
|
.unwrap();
|
|
|
|
// Should be able to get quality metrics
|
|
let metrics = quality_monitor
|
|
.get_task_quality_metrics(task_id)
|
|
.await
|
|
.unwrap();
|
|
assert!(metrics.is_some());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_metrics_record_batch_processed_signature() {
|
|
// Test that record_batch_processed method accepts correct parameters
|
|
let metrics = EtlMetrics::new();
|
|
|
|
let record_count = 100_usize;
|
|
let processing_time = Duration::from_millis(1000);
|
|
|
|
// Should accept 2 parameters: usize and Duration
|
|
metrics
|
|
.record_batch_processed(record_count, processing_time)
|
|
.await;
|
|
|
|
// Should be able to get batch stats
|
|
let batch_stats = metrics.get_batch_stats().await;
|
|
assert_eq!(batch_stats.total_batches, 1);
|
|
assert_eq!(batch_stats.total_records, 100);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_metrics_additional_methods() {
|
|
// Test that EtlMetrics has additional methods needed by engine
|
|
let metrics = EtlMetrics::new();
|
|
|
|
let task_id = "test_task";
|
|
|
|
// Should have record_data_loaded method
|
|
metrics.record_data_loaded(task_id, 50).await.unwrap();
|
|
|
|
// Should have record_validation_results method
|
|
let validation_results = serde_json::json!({"passed": 45, "failed": 5});
|
|
metrics
|
|
.record_validation_results(task_id, &validation_results)
|
|
.await
|
|
.unwrap();
|
|
|
|
// Should have record_aggregation_computed method
|
|
metrics
|
|
.record_aggregation_computed(task_id, 10)
|
|
.await
|
|
.unwrap();
|
|
|
|
// Should have record_generic_task_completed method
|
|
metrics
|
|
.record_generic_task_completed(task_id, 100)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_task_priority_type_exists() {
|
|
// Test that TaskPriority type exists and is usable
|
|
use rtx_etl::dag::TaskPriority;
|
|
|
|
let priority = TaskPriority::default();
|
|
|
|
// Should be a valid priority value
|
|
match priority {
|
|
TaskPriority::Low | TaskPriority::Medium | TaskPriority::High | TaskPriority::Critical => {
|
|
// Valid priority types
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_engine_functions_not_in_impl() {
|
|
// Test that standalone engine functions work correctly
|
|
let engine = EtlEngine::new().await.unwrap();
|
|
|
|
// Should be able to get execution status
|
|
let execution_id = uuid::Uuid::new_v4();
|
|
let status = engine.get_execution_status(execution_id).await;
|
|
assert!(status.is_none()); // No execution yet
|
|
|
|
// Should be able to get metrics
|
|
let metrics = engine.get_metrics().await;
|
|
assert!(metrics.get_overall_stats().await.total_tasks_executed >= 0);
|
|
}
|