Skip to content

Commit 018e4ce

Browse files
author
Test User
committed
fix(tests): replace #[test] with #[tokio::test] on 22 async tests in context_tests.rs Refs #2238
Removed `use tokio::test;` import which was implicitly shadowing the built-in `#[test]` attribute. Replaced all 22 `#[test]` annotations on async test functions with explicit `#[tokio::test]`. All 120 unit tests pass, clippy clean, fmt clean.
1 parent 907b964 commit 018e4ce

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

crates/terraphim_service/src/context_tests.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ mod tests {
1111
use terraphim_types::{
1212
ChatMessage, ContextItem, ContextType, ConversationId, Document, DocumentType, RoleName,
1313
};
14-
use tokio::test;
15-
1614
// Test fixtures
1715
fn create_test_config() -> ContextConfig {
1816
ContextConfig {
@@ -69,7 +67,7 @@ mod tests {
6967

7068
// Core functionality tests
7169

72-
#[test]
70+
#[tokio::test]
7371
async fn test_create_conversation() {
7472
let mut manager = ContextManager::new(create_test_config());
7573
let title = "Test Conversation".to_string();
@@ -92,7 +90,7 @@ mod tests {
9290
assert!(conv.global_context.is_empty());
9391
}
9492

95-
#[test]
93+
#[tokio::test]
9694
async fn test_create_conversation_with_empty_title() {
9795
let mut manager = ContextManager::new(create_test_config());
9896
let title = "".to_string();
@@ -109,7 +107,7 @@ mod tests {
109107
assert_eq!(conversation.unwrap().title, "");
110108
}
111109

112-
#[test]
110+
#[tokio::test]
113111
async fn test_list_conversations() {
114112
let mut manager = ContextManager::new(create_test_config());
115113

@@ -142,7 +140,7 @@ mod tests {
142140
assert_eq!(conversations[2].id, conv1);
143141
}
144142

145-
#[test]
143+
#[tokio::test]
146144
async fn test_get_conversation() {
147145
let mut manager = ContextManager::new(create_test_config());
148146
let conversation_id = manager
@@ -160,7 +158,7 @@ mod tests {
160158
assert!(result.is_none());
161159
}
162160

163-
#[test]
161+
#[tokio::test]
164162
async fn test_add_message_to_conversation() {
165163
let mut manager = ContextManager::new(create_test_config());
166164
let conversation_id = manager
@@ -180,7 +178,7 @@ mod tests {
180178
assert_eq!(conversation.messages[0].role, "user");
181179
}
182180

183-
#[test]
181+
#[tokio::test]
184182
async fn test_add_context_to_conversation() {
185183
let mut manager = ContextManager::new(create_test_config());
186184
let conversation_id = manager
@@ -209,7 +207,7 @@ mod tests {
209207
assert_eq!(conversation.global_context[0].content, context_item.content);
210208
}
211209

212-
#[test]
210+
#[tokio::test]
213211
async fn test_create_search_context() {
214212
let manager = ContextManager::new(create_test_config());
215213
let documents = create_test_documents(3);
@@ -232,7 +230,7 @@ mod tests {
232230
assert_eq!(context_item.metadata.get("result_count").unwrap(), "2");
233231
}
234232

235-
#[test]
233+
#[tokio::test]
236234
async fn test_create_search_context_with_empty_documents() {
237235
let manager = ContextManager::new(create_test_config());
238236
let documents: Vec<Document> = vec![];
@@ -245,7 +243,7 @@ mod tests {
245243
assert_eq!(context_item.metadata.get("result_count").unwrap(), "0");
246244
}
247245

248-
#[test]
246+
#[tokio::test]
249247
async fn test_create_document_context() {
250248
let manager = ContextManager::new(create_test_config());
251249
let document = create_test_document();
@@ -266,7 +264,7 @@ mod tests {
266264
assert_eq!(context_item.metadata.get("url").unwrap(), &document.url);
267265
}
268266

269-
#[test]
267+
#[tokio::test]
270268
async fn test_context_item_from_document() {
271269
let document = create_test_document();
272270
let context_item = ContextItem::from_document(&document);
@@ -282,7 +280,7 @@ mod tests {
282280
assert!(context_item.relevance_score.is_some());
283281
}
284282

285-
#[test]
283+
#[tokio::test]
286284
async fn test_context_item_from_search_result() {
287285
let documents = create_test_documents(3);
288286
let query = "test search";
@@ -300,7 +298,7 @@ mod tests {
300298

301299
// Edge case and error handling tests
302300

303-
#[test]
301+
#[tokio::test]
304302
async fn test_add_message_to_nonexistent_conversation() {
305303
let mut manager = ContextManager::new(create_test_config());
306304
let fake_id = ConversationId::from_string("non-existent".to_string());
@@ -311,7 +309,7 @@ mod tests {
311309
assert!(result.is_err());
312310
}
313311

314-
#[test]
312+
#[tokio::test]
315313
async fn test_add_context_to_nonexistent_conversation() {
316314
let mut manager = ContextManager::new(create_test_config());
317315
let fake_id = ConversationId::from_string("non-existent".to_string());
@@ -331,7 +329,7 @@ mod tests {
331329
assert!(result.is_err());
332330
}
333331

334-
#[test]
332+
#[tokio::test]
335333
async fn test_conversation_limits() {
336334
let config = ContextConfig {
337335
max_conversations_cache: 2,
@@ -368,7 +366,7 @@ mod tests {
368366
assert_eq!(latest.unwrap().title, "Conv 3");
369367
}
370368

371-
#[test]
369+
#[tokio::test]
372370
async fn test_max_context_exceeded() {
373371
let config = ContextConfig {
374372
max_conversations_cache: 10,
@@ -423,7 +421,7 @@ mod tests {
423421
assert!(result.is_err());
424422
}
425423

426-
#[test]
424+
#[tokio::test]
427425
async fn test_max_context_length_exceeded() {
428426
let config = ContextConfig {
429427
max_conversations_cache: 10,
@@ -453,7 +451,7 @@ mod tests {
453451
assert!(result.is_err());
454452
}
455453

456-
#[test]
454+
#[tokio::test]
457455
async fn test_conversation_cache_limits() {
458456
let config = ContextConfig {
459457
max_conversations_cache: 3,
@@ -497,7 +495,7 @@ mod tests {
497495
assert!(all_conversations.len() <= 3);
498496
}
499497

500-
#[test]
498+
#[tokio::test]
501499
async fn test_concurrent_access() {
502500
use std::sync::Arc;
503501
use tokio::sync::Mutex;
@@ -533,7 +531,7 @@ mod tests {
533531
assert_eq!(conversations.len(), 10);
534532
}
535533

536-
#[test]
534+
#[tokio::test]
537535
async fn test_default_search_results_limit() {
538536
let config = ContextConfig {
539537
max_conversations_cache: 10,
@@ -554,7 +552,7 @@ mod tests {
554552
assert!(!context_item.content.contains("Test Document 2"));
555553
}
556554

557-
#[test]
555+
#[tokio::test]
558556
async fn test_context_metadata_preservation() {
559557
let mut document = create_test_document();
560558
document.tags = Some(vec!["rust".to_string(), "test".to_string()]);
@@ -571,7 +569,7 @@ mod tests {
571569
assert_eq!(context_item.metadata.get("rank").unwrap(), "42");
572570
}
573571

574-
#[test]
572+
#[tokio::test]
575573
async fn test_conversation_role_assignment() {
576574
let mut manager = ContextManager::new(create_test_config());
577575

@@ -592,7 +590,7 @@ mod tests {
592590
assert_eq!(res_conversation.role, RoleName::new("researcher"));
593591
}
594592

595-
#[test]
593+
#[tokio::test]
596594
async fn test_timestamp_ordering() {
597595
let mut manager = ContextManager::new(create_test_config());
598596

0 commit comments

Comments
 (0)