71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
//! TDD tests for task execution functionality
|
|
//! These tests define expected behavior for task execution and metrics recording
|
|
|
|
use rtx_etl::{
|
|
dag::{Task, TaskType},
|
|
engine::EtlEngine,
|
|
monitoring::EtlMetrics,
|
|
};
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
#[tokio::test]
|
|
async fn test_task_execution_metrics_recording() {
|
|
// Test that task execution records metrics correctly with proper parameters
|
|
let metrics = Arc::new(EtlMetrics::new());
|
|
|
|
// Create a test task
|
|
let task = create_test_task();
|
|
|
|
// Record task execution with all required parameters
|
|
let task_id = &task.id;
|
|
let task_type = &task.task_type;
|
|
let execution_time = Duration::from_millis(500);
|
|
let success = true;
|
|
|
|
// Should be able to record with 4 parameters as implemented
|
|
metrics
|
|
.record_task_execution(task_id, task_type, execution_time, success)
|
|
.await;
|
|
|
|
// Verify metrics were recorded
|
|
let stats = metrics.get_task_stats(task_id).await;
|
|
assert!(stats.is_some());
|
|
|
|
let task_stats = stats.unwrap();
|
|
assert_eq!(task_stats.total_executions, 1);
|
|
assert_eq!(task_stats.successful_executions, 1);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_task_has_required_fields() {
|
|
// Test that Task struct has the required fields
|
|
let task = create_test_task();
|
|
|
|
// Task should have id field
|
|
assert!(!task.id.is_empty());
|
|
|
|
// Task should have task_type field
|
|
match task.task_type {
|
|
TaskType::Extract | TaskType::Transform | TaskType::Load => {
|
|
// Valid task types
|
|
}
|
|
_ => panic!("Invalid task type"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_task_creation_with_config() {
|
|
// Test creating task with configuration
|
|
let task = Task::new("test_task".to_string(), TaskType::Extract);
|
|
|
|
// Should have basic properties
|
|
assert_eq!(task.id, "test_task");
|
|
assert_eq!(task.task_type, TaskType::Extract);
|
|
}
|
|
|
|
// Helper function to create test task
|
|
fn create_test_task() -> Task {
|
|
Task::new("test_task_1".to_string(), TaskType::Extract)
|
|
}
|