Skip to content

Commit f21a23c

Browse files
AlexMikhalevclaude
andcommitted
test: add serial_test and cleanup to conversation_service tests
The conversation_service tests were failing in CI due to shared global DeviceStorage state. When tests run in parallel, they interfere with each other because they all share the same conversations/index.json. This fix: - Adds #[serial] attribute to all conversation_service tests to ensure sequential execution - Adds a cleanup_conversations helper function - Cleans up existing conversations before tests that depend on counts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 49aaf77 commit f21a23c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

crates/terraphim_service/src/conversation_service.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,23 @@ impl Default for ConversationService {
238238
#[cfg(test)]
239239
mod tests {
240240
use super::*;
241+
use serial_test::serial;
241242
use terraphim_persistence::DeviceStorage;
242243
use terraphim_types::ChatMessage;
243244

245+
/// Helper function to clean up all conversations before a test
246+
async fn cleanup_conversations(service: &ConversationService) {
247+
let all = service
248+
.list_conversations(ConversationFilter::default())
249+
.await
250+
.unwrap_or_default();
251+
for conv in all {
252+
let _ = service.delete_conversation(&conv.id).await;
253+
}
254+
}
255+
244256
#[tokio::test]
257+
#[serial]
245258
async fn test_create_and_get_conversation() {
246259
// Initialize memory-only storage for testing
247260
let _ = DeviceStorage::init_memory_only().await.unwrap();
@@ -258,12 +271,16 @@ mod tests {
258271
}
259272

260273
#[tokio::test]
274+
#[serial]
261275
async fn test_list_and_filter_conversations() {
262276
// Initialize memory-only storage for testing
263277
let _ = DeviceStorage::init_memory_only().await.unwrap();
264278

265279
let service = ConversationService::new();
266280

281+
// Clean up any existing conversations first
282+
cleanup_conversations(&service).await;
283+
267284
// Create conversations with different roles
268285
service
269286
.create_conversation("Test 1".to_string(), RoleName::new("Role A"))
@@ -297,12 +314,16 @@ mod tests {
297314
}
298315

299316
#[tokio::test]
317+
#[serial]
300318
async fn test_search_conversations() {
301319
// Initialize memory-only storage for testing
302320
let _ = DeviceStorage::init_memory_only().await.unwrap();
303321

304322
let service = ConversationService::new();
305323

324+
// Clean up any existing conversations first
325+
cleanup_conversations(&service).await;
326+
306327
service
307328
.create_conversation("Machine Learning".to_string(), RoleName::new("Test"))
308329
.await
@@ -318,6 +339,7 @@ mod tests {
318339
}
319340

320341
#[tokio::test]
342+
#[serial]
321343
async fn test_export_import_conversation() {
322344
// Initialize memory-only storage for testing
323345
let _ = DeviceStorage::init_memory_only().await.unwrap();
@@ -346,12 +368,16 @@ mod tests {
346368
}
347369

348370
#[tokio::test]
371+
#[serial]
349372
async fn test_get_statistics() {
350373
// Initialize memory-only storage for testing
351374
let _ = DeviceStorage::init_memory_only().await.unwrap();
352375

353376
let service = ConversationService::new();
354377

378+
// Clean up any existing conversations first
379+
cleanup_conversations(&service).await;
380+
355381
let mut conv1 = service
356382
.create_conversation("Test 1".to_string(), RoleName::new("Role A"))
357383
.await

0 commit comments

Comments
 (0)