import Foundation import XCTest @testable import bitchat final class GossipSyncManagerTests: XCTestCase { func testConcurrentPacketIntakeAndSyncRequest() { let manager = GossipSyncManager(myPeerID: "0102030405060708") let delegate = RecordingDelegate() let sendExpectation = expectation(description: "sync request sent") delegate.onSend = { sendExpectation.fulfill() } manager.delegate = delegate let iterations = 200 let group = DispatchGroup() for i in 0.. Void)? private(set) var lastPacket: BitchatPacket? private let lock = NSLock() func sendPacket(_ packet: BitchatPacket) { lock.lock() lastPacket = packet lock.unlock() onSend?() } func sendPacket(to peerID: String, packet: BitchatPacket) { sendPacket(packet) } func signPacketForBroadcast(_ packet: BitchatPacket) -> BitchatPacket { packet } }