Update build/test scripts with clean progress indicators and minimal output
This commit is contained in:
@@ -1188,112 +1188,3 @@ pub async fn start_openrpc_servers(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::supervisor::Supervisor;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_supervisor_rpc_creation() {
|
||||
// Test that we can create a supervisor and use it with RPC
|
||||
use crate::supervisor::SupervisorBuilder;
|
||||
|
||||
let supervisor = SupervisorBuilder::new()
|
||||
.redis_url("redis://localhost:6379")
|
||||
.namespace("test")
|
||||
.build()
|
||||
.await;
|
||||
|
||||
// Just test that we can build a supervisor
|
||||
assert!(supervisor.is_ok() || supervisor.is_err()); // Either way is fine for this test
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_process_manager_type_parsing() {
|
||||
assert!(parse_process_manager_type("simple", None).is_ok());
|
||||
assert!(parse_process_manager_type("tmux", Some("session".to_string())).is_ok());
|
||||
assert!(parse_process_manager_type("Simple", None).is_ok());
|
||||
assert!(parse_process_manager_type("TMUX", Some("session".to_string())).is_ok());
|
||||
assert!(parse_process_manager_type("invalid", None).is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_job_api_methods() {
|
||||
let supervisor = Arc::new(Mutex::new(Supervisor::default()));
|
||||
let mut sup = supervisor.lock().await;
|
||||
sup.add_user_secret("test-secret".to_string());
|
||||
drop(sup);
|
||||
|
||||
// Test jobs.create
|
||||
let job = crate::job::JobBuilder::new()
|
||||
.caller_id("test")
|
||||
.context_id("test")
|
||||
.payload("test")
|
||||
.runner("test_runner")
|
||||
.executor("osis")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let params = RunJobParams {
|
||||
job: job.clone(),
|
||||
};
|
||||
|
||||
// Set the API key in thread-local for the test
|
||||
set_current_api_key(Some("test-secret".to_string()));
|
||||
|
||||
let result = supervisor.jobs_create(params).await;
|
||||
// Should work or fail gracefully without Redis
|
||||
assert!(result.is_ok() || result.is_err());
|
||||
|
||||
// Test job.start
|
||||
let start_params = StartJobParams {
|
||||
job_id: "test-job".to_string(),
|
||||
};
|
||||
|
||||
let result = supervisor.job_start(start_params).await;
|
||||
// Should fail gracefully without Redis/job
|
||||
assert!(result.is_err());
|
||||
|
||||
// Test invalid secret
|
||||
let invalid_params = StartJobParams {
|
||||
job_id: "test-job".to_string(),
|
||||
};
|
||||
|
||||
let result = supervisor.job_start(invalid_params).await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_result_serialization() {
|
||||
let success = JobResult::Success { success: "test output".to_string() };
|
||||
let json = serde_json::to_string(&success).unwrap();
|
||||
assert!(json.contains("success"));
|
||||
assert!(json.contains("test output"));
|
||||
|
||||
let error = JobResult::Error { error: "test error".to_string() };
|
||||
let json = serde_json::to_string(&error).unwrap();
|
||||
assert!(json.contains("error"));
|
||||
assert!(json.contains("test error"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_status_response_serialization() {
|
||||
let status = JobStatusResponse {
|
||||
job_id: "test-job".to_string(),
|
||||
status: "running".to_string(),
|
||||
created_at: "2023-01-01T00:00:00Z".to_string(),
|
||||
started_at: Some("2023-01-01T00:00:05Z".to_string()),
|
||||
completed_at: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&status).unwrap();
|
||||
assert!(json.contains("test-job"));
|
||||
assert!(json.contains("running"));
|
||||
assert!(json.contains("2023-01-01T00:00:00Z"));
|
||||
|
||||
let deserialized: JobStatusResponse = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(deserialized.job_id, "test-job");
|
||||
assert_eq!(deserialized.status, "running");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,47 +266,4 @@ impl Default for Services {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_api_key_service() {
|
||||
let service = ApiKeyService::new();
|
||||
|
||||
let key = ApiKey {
|
||||
key: "test-key".to_string(),
|
||||
name: "test".to_string(),
|
||||
scope: ApiKeyScope::User,
|
||||
};
|
||||
|
||||
service.store(key.clone()).await.unwrap();
|
||||
assert_eq!(service.get("test-key").await.unwrap().name, "test");
|
||||
assert_eq!(service.list().await.len(), 1);
|
||||
|
||||
service.remove("test-key").await;
|
||||
assert!(service.get("test-key").await.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_runner_service() {
|
||||
let service = RunnerService::new();
|
||||
|
||||
let metadata = RunnerMetadata {
|
||||
id: "runner1".to_string(),
|
||||
name: "runner1".to_string(),
|
||||
queue: "queue1".to_string(),
|
||||
registered_at: "2024-01-01".to_string(),
|
||||
registered_by: "admin".to_string(),
|
||||
};
|
||||
|
||||
service.store(metadata.clone()).await.unwrap();
|
||||
assert_eq!(service.get("runner1").await.unwrap().name, "runner1");
|
||||
assert_eq!(service.count().await, 1);
|
||||
|
||||
service.remove("runner1").await;
|
||||
assert!(service.get("runner1").await.is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1030,78 +1030,4 @@ impl Default for Supervisor {
|
||||
client: Client::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_supervisor_creation() {
|
||||
let supervisor = Supervisor::builder()
|
||||
.redis_url("redis://localhost:6379")
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(supervisor.list_runners().len(), 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_runner() {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let config = RunnerConfig::new(
|
||||
"test_actor".to_string(),
|
||||
"test_actor".to_string(),
|
||||
"".to_string(),
|
||||
PathBuf::from("/usr/bin/test_actor"),
|
||||
"redis://localhost:6379".to_string(),
|
||||
);
|
||||
|
||||
let runner = Runner::from_config(config.clone());
|
||||
let mut supervisor = Supervisor::builder()
|
||||
.redis_url("redis://localhost:6379")
|
||||
.add_runner(runner)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(supervisor.list_runners().len(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_multiple_runners() {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let config1 = RunnerConfig::new(
|
||||
"sal_actor".to_string(),
|
||||
"sal_actor".to_string(),
|
||||
"".to_string(),
|
||||
PathBuf::from("/usr/bin/sal_actor"),
|
||||
"redis://localhost:6379".to_string(),
|
||||
);
|
||||
|
||||
let config2 = RunnerConfig::new(
|
||||
"osis_actor".to_string(),
|
||||
"osis_actor".to_string(),
|
||||
"".to_string(),
|
||||
PathBuf::from("/usr/bin/osis_actor"),
|
||||
"redis://localhost:6379".to_string(),
|
||||
);
|
||||
|
||||
let runner1 = Runner::from_config(config1);
|
||||
let runner2 = Runner::from_config(config2);
|
||||
|
||||
let supervisor = Supervisor::builder()
|
||||
.redis_url("redis://localhost:6379")
|
||||
.add_runner(runner1)
|
||||
.add_runner(runner2)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(supervisor.list_runners().len(), 2);
|
||||
assert!(supervisor.get_runner("sal_actor").is_some());
|
||||
assert!(supervisor.get_runner("osis_actor").is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user