mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 04:05:20 +00:00
Fix test suite peer ID collisions (#764)
Use unique peer IDs for each test suite to prevent global registry collisions when Swift Testing runs suites in parallel. - PrivateChatE2ETests: PRIV_* prefix - PublicChatE2ETests: PUB_* prefix - Update all peer ID references to use actual instance IDs This fixes the race condition where simplePublicMessage() was receiving duplicate deliveries due to registry contamination. Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -21,11 +21,11 @@ struct PrivateChatE2ETests {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
MockBLEService.resetTestBus()
|
MockBLEService.resetTestBus()
|
||||||
|
|
||||||
// Create services
|
// Create services with unique peer IDs to avoid collision with other test suites
|
||||||
alice = MockBLEService(peerID: TestConstants.testPeerID1, nickname: TestConstants.testNickname1)
|
alice = MockBLEService(peerID: "PRIV_ALICE_", nickname: TestConstants.testNickname1)
|
||||||
bob = MockBLEService(peerID: TestConstants.testPeerID2, nickname: TestConstants.testNickname2)
|
bob = MockBLEService(peerID: "PRIV_BOB___", nickname: TestConstants.testNickname2)
|
||||||
charlie = MockBLEService(peerID: TestConstants.testPeerID3, nickname: TestConstants.testNickname3)
|
charlie = MockBLEService(peerID: "PRIV_CHARLE", nickname: TestConstants.testNickname3)
|
||||||
mockKeychain = MockKeychain()
|
mockKeychain = MockKeychain()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ struct PrivateChatE2ETests {
|
|||||||
// Alice sends private message to Bob
|
// Alice sends private message to Bob
|
||||||
alice.sendPrivateMessage(
|
alice.sendPrivateMessage(
|
||||||
TestConstants.testMessage1,
|
TestConstants.testMessage1,
|
||||||
to: TestConstants.testPeerID2,
|
to: PeerID(str: bob.peerID),
|
||||||
recipientNickname: TestConstants.testNickname2
|
recipientNickname: TestConstants.testNickname2
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ struct PrivateChatE2ETests {
|
|||||||
// Alice sends private message to Bob
|
// Alice sends private message to Bob
|
||||||
alice.sendPrivateMessage(
|
alice.sendPrivateMessage(
|
||||||
TestConstants.testMessage1,
|
TestConstants.testMessage1,
|
||||||
to: TestConstants.testPeerID2,
|
to: PeerID(str: bob.peerID),
|
||||||
recipientNickname: TestConstants.testNickname2
|
recipientNickname: TestConstants.testNickname2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -97,10 +97,10 @@ struct PrivateChatE2ETests {
|
|||||||
Issue.record("Charlie should not receive")
|
Issue.record("Charlie should not receive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alice.sendPrivateMessage(
|
alice.sendPrivateMessage(
|
||||||
TestConstants.testMessage1,
|
TestConstants.testMessage1,
|
||||||
to: TestConstants.testPeerID2,
|
to: PeerID(str: bob.peerID),
|
||||||
recipientNickname: TestConstants.testNickname2
|
recipientNickname: TestConstants.testNickname2
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -120,10 +120,10 @@ struct PrivateChatE2ETests {
|
|||||||
|
|
||||||
// Establish encrypted session
|
// Establish encrypted session
|
||||||
do {
|
do {
|
||||||
let handshake1 = try aliceManager.initiateHandshake(with: TestConstants.testPeerID2)
|
let handshake1 = try aliceManager.initiateHandshake(with: PeerID(str: bob.peerID))
|
||||||
let handshake2 = try bobManager.handleIncomingHandshake(from: TestConstants.testPeerID1, message: handshake1)!
|
let handshake2 = try bobManager.handleIncomingHandshake(from: PeerID(str: alice.peerID), message: handshake1)!
|
||||||
let handshake3 = try aliceManager.handleIncomingHandshake(from: TestConstants.testPeerID2, message: handshake2)!
|
let handshake3 = try aliceManager.handleIncomingHandshake(from: PeerID(str: bob.peerID), message: handshake2)!
|
||||||
_ = try bobManager.handleIncomingHandshake(from: TestConstants.testPeerID1, message: handshake3)
|
_ = try bobManager.handleIncomingHandshake(from: PeerID(str: alice.peerID), message: handshake3)
|
||||||
} catch {
|
} catch {
|
||||||
Issue.record("Failed to establish Noise session: \(error)")
|
Issue.record("Failed to establish Noise session: \(error)")
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ struct PrivateChatE2ETests {
|
|||||||
let message = BitchatMessage(packet.payload),
|
let message = BitchatMessage(packet.payload),
|
||||||
message.isPrivate {
|
message.isPrivate {
|
||||||
do {
|
do {
|
||||||
let encrypted = try aliceManager.encrypt(packet.payload, for: TestConstants.testPeerID2)
|
let encrypted = try aliceManager.encrypt(packet.payload, for: PeerID(str: bob.peerID))
|
||||||
let encryptedPacket = BitchatPacket(
|
let encryptedPacket = BitchatPacket(
|
||||||
type: 0x02, // Encrypted message type
|
type: 0x02, // Encrypted message type
|
||||||
senderID: packet.senderID,
|
senderID: packet.senderID,
|
||||||
@@ -157,7 +157,7 @@ struct PrivateChatE2ETests {
|
|||||||
// Decrypt incoming encrypted messages
|
// Decrypt incoming encrypted messages
|
||||||
if packet.type == 0x02 {
|
if packet.type == 0x02 {
|
||||||
do {
|
do {
|
||||||
let decrypted = try bobManager.decrypt(packet.payload, from: TestConstants.testPeerID1)
|
let decrypted = try bobManager.decrypt(packet.payload, from: PeerID(str: alice.peerID))
|
||||||
if let message = BitchatMessage(decrypted) {
|
if let message = BitchatMessage(decrypted) {
|
||||||
#expect(message.content == TestConstants.testMessage1)
|
#expect(message.content == TestConstants.testMessage1)
|
||||||
#expect(message.isPrivate)
|
#expect(message.isPrivate)
|
||||||
@@ -189,7 +189,7 @@ struct PrivateChatE2ETests {
|
|||||||
// Bob relays private messages for Charlie
|
// Bob relays private messages for Charlie
|
||||||
bob.packetDeliveryHandler = { packet in
|
bob.packetDeliveryHandler = { packet in
|
||||||
if let recipientID = packet.recipientID,
|
if let recipientID = packet.recipientID,
|
||||||
String(data: recipientID, encoding: .utf8) == TestConstants.testPeerID3 {
|
String(data: recipientID, encoding: .utf8) == charlie.peerID {
|
||||||
// Relay to Charlie
|
// Relay to Charlie
|
||||||
var relayPacket = packet
|
var relayPacket = packet
|
||||||
relayPacket.ttl = packet.ttl - 1
|
relayPacket.ttl = packet.ttl - 1
|
||||||
@@ -208,7 +208,7 @@ struct PrivateChatE2ETests {
|
|||||||
// Alice sends private message to Charlie (through Bob)
|
// Alice sends private message to Charlie (through Bob)
|
||||||
alice.sendPrivateMessage(
|
alice.sendPrivateMessage(
|
||||||
TestConstants.testMessage1,
|
TestConstants.testMessage1,
|
||||||
to: TestConstants.testPeerID3,
|
to: PeerID(str: charlie.peerID),
|
||||||
recipientNickname: TestConstants.testNickname3
|
recipientNickname: TestConstants.testNickname3
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ struct PublicChatE2ETests {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
MockBLEService.resetTestBus()
|
MockBLEService.resetTestBus()
|
||||||
|
|
||||||
// Create mock services
|
// Create mock services with unique peer IDs to avoid collision with other test suites
|
||||||
alice = MockBLEService(peerID: TestConstants.testPeerID1, nickname: TestConstants.testNickname1)
|
alice = MockBLEService(peerID: "PUB_ALICE__", nickname: TestConstants.testNickname1)
|
||||||
bob = MockBLEService(peerID: TestConstants.testPeerID2, nickname: TestConstants.testNickname2)
|
bob = MockBLEService(peerID: "PUB_BOB____", nickname: TestConstants.testNickname2)
|
||||||
charlie = MockBLEService(peerID: TestConstants.testPeerID3, nickname: TestConstants.testNickname3)
|
charlie = MockBLEService(peerID: "PUB_CHARLIE", nickname: TestConstants.testNickname3)
|
||||||
david = MockBLEService(peerID: TestConstants.testPeerID4, nickname: TestConstants.testNickname4)
|
david = MockBLEService(peerID: "PUB_DAVID__", nickname: TestConstants.testNickname4)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Basic Broadcasting Tests
|
// MARK: - Basic Broadcasting Tests
|
||||||
|
|||||||
Reference in New Issue
Block a user