Skip to content

Commit b42e206

Browse files
authored
Fix test interference from shared notification IDs (#524)
Test fixtures in IncomingMessageWriterExplodeTests and ExpiredConversationsWorkerTests both used the hardcoded conversation ID "test-conversation-id". When Swift Testing runs suites in parallel, a .conversationExpired notification posted by one suite's test could be captured by another suite's NotificationCapture, causing testPastDatePostsExpiredNotification to see count == 2 instead of 1. Fix: use unique UUIDs for conversation IDs in test fixtures and filter captured notifications by conversationId.
1 parent 4677e43 commit b42e206

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

ConvosCore/Tests/ConvosCoreTests/ExpiredConversationsWorkerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private class ExpiredWorkerTestFixtures {
170170
let databaseManager: MockDatabaseManager
171171
let appLifecycle: MockAppLifecycleProvider
172172
let sessionManager: MockInboxesService
173-
let conversationId: String = "test-conversation-id"
173+
let conversationId: String = "expired-worker-test-\(UUID().uuidString)"
174174
let inboxId: String = "test-inbox-id"
175175
let clientId: String = "test-client-id"
176176

ConvosCore/Tests/ConvosCoreTests/IncomingMessageWriterExplodeTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ struct IncomingMessageWriterExplodeTests {
230230
try await Task.sleep(for: .milliseconds(100))
231231

232232
#expect(capture.hasNotification(.conversationExpired))
233-
let notifications = capture.notifications(named: .conversationExpired)
234-
#expect(notifications.count == 1)
235-
let userInfo = notifications.first?.userInfo
236-
#expect(userInfo?["conversationId"] as? String == fixtures.conversationId)
233+
let matching = capture.notifications(named: .conversationExpired).filter {
234+
$0.userInfo?["conversationId"] as? String == fixtures.conversationId
235+
}
236+
#expect(matching.count == 1)
237237
}
238238

239239
@Test("Writes expiresAt to database")
@@ -266,7 +266,7 @@ struct IncomingMessageWriterExplodeTests {
266266
private class ExplodeTestFixtures {
267267
let databaseManager: MockDatabaseManager
268268
let writer: IncomingMessageWriter
269-
let conversationId: String = "test-conversation-id"
269+
let conversationId: String = "explode-test-\(UUID().uuidString)"
270270
let creatorInboxId: String = "creator-inbox-id"
271271
let currentInboxId: String = "current-inbox-id"
272272
let clientId: String = "test-client-id"

0 commit comments

Comments
 (0)