use crate::api::gpu_handlers::{
BatchConfig, GpuBatchRequest, GpuBatchResponse, GpuBatchResult, GpuBatchStats,
GpuStatusResponse,
};
#[cfg(feature = "gpu")]
use crate::api::gpu_handlers::ContinuousBatchResponse;
#[test]
fn test_batch_config_extreme_values() {
let config = BatchConfig {
window_ms: 1, min_batch: 1, optimal_batch: 1, max_batch: 1, queue_size: 1, gpu_threshold: 1, };
assert!(config.should_process(1));
assert!(config.meets_minimum(1));
assert!(!config.should_process(0));
assert!(!config.meets_minimum(0));
}
#[test]
fn test_batch_config_huge_values() {
let config = BatchConfig {
window_ms: 60_000, min_batch: 1000, optimal_batch: 10_000, max_batch: 100_000, queue_size: 1_000_000, gpu_threshold: 50_000, };
assert!(!config.should_process(9999));
assert!(config.should_process(10_000));
assert!(!config.meets_minimum(999));
assert!(config.meets_minimum(1000));
}
#[test]
fn test_batch_config_inverted_thresholds() {
let config = BatchConfig {
window_ms: 50,
min_batch: 100, optimal_batch: 50, max_batch: 10, queue_size: 1024,
gpu_threshold: 32,
};
assert!(config.should_process(50));
assert!(config.meets_minimum(100));
}
#[test]
fn test_batch_config_zero_window() {
let config = BatchConfig {
window_ms: 0, min_batch: 4,
optimal_batch: 32,
max_batch: 64,
queue_size: 1024,
gpu_threshold: 32,
};
assert!(config.meets_minimum(4));
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_single_path() {
let response = ContinuousBatchResponse::single(vec![1, 2, 3], 1, 10.0);
assert!(!response.batched);
assert_eq!(response.batch_size, 1);
assert_eq!(response.token_ids, vec![1, 2, 3]);
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_batched_path() {
let response = ContinuousBatchResponse::batched(vec![1, 2, 3, 4, 5], 2, 8, 5.0);
assert!(response.batched);
assert_eq!(response.batch_size, 8);
assert_eq!(response.prompt_len, 2);
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_empty_tokens() {
let response = ContinuousBatchResponse::single(vec![], 0, 0.0);
assert!(response.token_ids.is_empty());
assert!(!response.batched);
assert_eq!(response.batch_size, 1);
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_huge_batch_size() {
let response = ContinuousBatchResponse::batched(
vec![1, 2, 3],
1,
1_000_000, 0.001, );
assert!(response.batched);
assert_eq!(response.batch_size, 1_000_000);
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_infinite_latency() {
let response = ContinuousBatchResponse::batched(vec![1], 1, 8, f64::INFINITY);
assert!(response.latency_ms.is_infinite());
}
#[cfg(feature = "gpu")]
#[tokio::test]
async fn test_continuous_batch_response_nan_latency() {
let response = ContinuousBatchResponse::batched(vec![1], 1, 8, f64::NAN);
assert!(response.latency_ms.is_nan());
}
#[test]
fn test_gpu_batch_request_empty_prompts() {
let request = GpuBatchRequest {
prompts: vec![],
max_tokens: 100,
temperature: 1.0,
top_k: 40,
stop: vec![],
};
assert!(request.prompts.is_empty());
}
#[test]
fn test_gpu_batch_request_single_empty_prompt() {
let request = GpuBatchRequest {
prompts: vec![String::new()],
max_tokens: 100,
temperature: 1.0,
top_k: 40,
stop: vec![],
};
assert_eq!(request.prompts.len(), 1);
assert!(request.prompts[0].is_empty());
}
#[test]
fn test_gpu_batch_request_huge_prompts() {
let prompts: Vec<String> = (0..1000).map(|i| format!("Prompt {}", i)).collect();
let request = GpuBatchRequest {
prompts,
max_tokens: 1,
temperature: 0.0,
top_k: 1,
stop: vec![],
};
assert_eq!(request.prompts.len(), 1000);
}
#[test]
fn test_gpu_batch_request_long_prompt() {
let long_prompt = "x".repeat(1_000_000);
let request = GpuBatchRequest {
prompts: vec![long_prompt.clone()],
max_tokens: 1,
temperature: 0.0,
top_k: 1,
stop: vec![],
};
assert_eq!(request.prompts[0].len(), 1_000_000);
}
#[test]
fn test_gpu_batch_request_zero_max_tokens() {
let request = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 0, temperature: 0.0,
top_k: 1,
stop: vec![],
};
assert_eq!(request.max_tokens, 0);
}
#[test]
fn test_gpu_batch_request_huge_max_tokens() {
let request = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: usize::MAX, temperature: 0.0,
top_k: 1,
stop: vec![],
};
assert_eq!(request.max_tokens, usize::MAX);
}
#[test]
fn test_gpu_batch_request_extreme_temperature() {
let request_zero = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 10,
temperature: 0.0,
top_k: 1,
stop: vec![],
};
assert_eq!(request_zero.temperature, 0.0);
let request_inf = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 10,
temperature: f32::INFINITY,
top_k: 1,
stop: vec![],
};
assert!(request_inf.temperature.is_infinite());
}
#[test]
fn test_gpu_batch_request_extreme_top_k() {
let request = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 10,
temperature: 0.0,
top_k: 0, stop: vec![],
};
assert_eq!(request.top_k, 0);
let request_huge = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 10,
temperature: 0.0,
top_k: 1_000_000, stop: vec![],
};
assert_eq!(request_huge.top_k, 1_000_000);
}
#[test]
fn test_gpu_batch_request_with_stop_tokens() {
let request = GpuBatchRequest {
prompts: vec!["test".to_string()],
max_tokens: 100,
temperature: 0.7,
top_k: 40,
stop: vec!["END".to_string(), "\n".to_string(), "STOP".to_string()],
};
assert_eq!(request.stop.len(), 3);
}
#[test]
fn test_gpu_batch_response_empty_results() {
let response = GpuBatchResponse {
results: vec![],
stats: GpuBatchStats {
batch_size: 0,
gpu_used: false,
total_tokens: 0,
processing_time_ms: 0.0,
throughput_tps: 0.0,
},
};
assert!(response.results.is_empty());
assert_eq!(response.stats.batch_size, 0);
}
#[test]
fn test_gpu_batch_response_mismatched_stats() {
let response = GpuBatchResponse {
results: vec![GpuBatchResult {
index: 0,
token_ids: vec![1, 2, 3],
text: "test".to_string(),
num_generated: 3,
}],
stats: GpuBatchStats {
batch_size: 100, gpu_used: true,
total_tokens: 1000,
processing_time_ms: 1.0,
throughput_tps: 1000.0,
},
};
assert_eq!(response.results.len(), 1);
assert_eq!(response.stats.batch_size, 100); }
#[test]
fn test_gpu_batch_result_empty_tokens() {
let result = GpuBatchResult {
index: 0,
token_ids: vec![],
text: String::new(),
num_generated: 0,
};
assert!(result.token_ids.is_empty());
assert_eq!(result.num_generated, 0);
}
#[test]
fn test_gpu_batch_result_huge_token_list() {
let token_ids: Vec<u32> = (0..10000).collect();
let result = GpuBatchResult {
index: 0,
token_ids,
text: "lots of tokens".to_string(),
num_generated: 10000,
};
assert_eq!(result.token_ids.len(), 10000);
}
#[test]
fn test_gpu_batch_result_unicode_text() {
let result = GpuBatchResult {
index: 0,
token_ids: vec![1, 2, 3, 4, 5],
text: "日本語 🎉🎊🎈 \u{0000}\u{FFFF}".to_string(),
num_generated: 5,
};
assert!(!result.text.is_empty());
}
#[test]
fn test_gpu_batch_result_large_index() {
let result = GpuBatchResult {
index: usize::MAX,
token_ids: vec![1],
text: "max index".to_string(),
num_generated: 1,
};
assert_eq!(result.index, usize::MAX);
}
#[test]
fn test_gpu_batch_stats_zero_throughput() {
let stats = GpuBatchStats {
batch_size: 1,
gpu_used: false,
total_tokens: 0,
processing_time_ms: 1000.0, throughput_tps: 0.0,
};
assert_eq!(stats.throughput_tps, 0.0);
}
#[test]
fn test_gpu_batch_stats_infinite_throughput() {
let stats = GpuBatchStats {
batch_size: 1,
gpu_used: true,
total_tokens: 1000,
processing_time_ms: 0.0, throughput_tps: f64::INFINITY,
};
assert!(stats.throughput_tps.is_infinite());
}
#[test]
fn test_gpu_batch_stats_nan_values() {
let stats = GpuBatchStats {
batch_size: 1,
gpu_used: false,
total_tokens: 0,
processing_time_ms: f64::NAN,
throughput_tps: f64::NAN,
};
assert!(stats.throughput_tps.is_nan());
assert!(stats.processing_time_ms.is_nan());
}
include!("gpu_batch_02.rs");