From 7c920e0bf288afe3410258502bbd00b01edfa8a4 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 27 Jul 2026 23:55:49 +0300 Subject: [PATCH] test: remove asynchronous suite flakes --- bitchatTests/AppArchitectureTests.swift | 22 ++++++++++++++----- .../NoiseEncryptionServiceTests.swift | 3 +-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bitchatTests/AppArchitectureTests.swift b/bitchatTests/AppArchitectureTests.swift index 2fdb94df..bc1f239e 100644 --- a/bitchatTests/AppArchitectureTests.swift +++ b/bitchatTests/AppArchitectureTests.swift @@ -81,6 +81,16 @@ private func waitUntil( } } +@MainActor +private func drainArchitecturePublicationQueue() async { + for _ in 0..<5 { + await withCheckedContinuation { continuation in + DispatchQueue.main.async { continuation.resume() } + } + await Task.yield() + } +} + @Suite("App Architecture Tests", .serialized) struct AppArchitectureTests { @@ -671,7 +681,8 @@ struct AppArchitectureTests { @Test("PeerListModel publishes mesh and geohash directory state") @MainActor func peerListModelPublishesDirectoryState() async { - let viewModel = makeArchitectureViewModel() + let locationManager = makeArchitectureLocationManager() + let viewModel = makeArchitectureViewModel(locationManager: locationManager) guard let transport = viewModel.meshService as? MockTransport else { Issue.record("Expected ChatViewModel meshService to be a MockTransport in architecture tests") return @@ -681,7 +692,6 @@ struct AppArchitectureTests { let otherPeerID = PeerID(str: "0011223344556677") let geohash = "9q8yy" let remoteGeoID = String(repeating: "b", count: 64) - let locationManager = makeArchitectureLocationManager() let locationChannelsModel = LocationChannelsModel(manager: locationManager) let otherNoiseKey = Data((0..<32).map(UInt8.init)) let verifiedFingerprint = otherNoiseKey.sha256Fingerprint() @@ -711,17 +721,19 @@ struct AppArchitectureTests { locationManager.select(.location(GeohashChannel(level: .city, geohash: geohash))) await waitUntil { if case .location(let channel) = locationManager.selectedChannel { - return channel.geohash == geohash && !viewModel.allPeers.isEmpty + return channel.geohash == geohash && + viewModel.currentGeohash == geohash && + !viewModel.allPeers.isEmpty } return false } - viewModel.participantTracker.setActiveGeohash(geohash) - viewModel.teleportedGeo = Set([remoteGeoID]) viewModel.participantTracker.recordParticipant(pubkeyHex: remoteGeoID, geohash: geohash) if let myGeoID = try? viewModel.idBridge.deriveIdentity(forGeohash: geohash).publicKeyHex.lowercased() { viewModel.participantTracker.recordParticipant(pubkeyHex: myGeoID, geohash: geohash) } + await drainArchitecturePublicationQueue() + viewModel.teleportedGeo = Set([remoteGeoID]) let peerListModel = PeerListModel( chatViewModel: viewModel, diff --git a/bitchatTests/Services/NoiseEncryptionServiceTests.swift b/bitchatTests/Services/NoiseEncryptionServiceTests.swift index a2031983..943687d2 100644 --- a/bitchatTests/Services/NoiseEncryptionServiceTests.swift +++ b/bitchatTests/Services/NoiseEncryptionServiceTests.swift @@ -715,8 +715,7 @@ struct NoiseEncryptionServiceTests { // setup handshake below, where bob is the responder. At 0.06 a // preempted runner could fire it mid-setup, tear down the half-open // responder, and make message 3 be answered as a fresh initiation. - ordinaryResponderHandshakeTimeout: 1.0, - ordinaryReconnectRollbackCooldown: 0.3 + ordinaryResponderHandshakeTimeout: 1.0 ) let mallory = NoiseEncryptionService(keychain: MockKeychain()) let alicePeerID = PeerID(publicKey: alice.getStaticPublicKeyData())