Skip to content

Commit

Permalink
update peer test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Nov 1, 2024
1 parent 7cc9383 commit 9698005
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 0 additions & 2 deletions Networking/Sources/Networking/Peer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ final class PeerImpl<Handler: StreamHandler>: Sendable {
)
connections.byAddr[address] = conn
connections.byId[conn.id] = conn
logger.debug("reconnectted", metadata: ["address": "\(address)", "role": "\(role)"])
}
}
}
Expand Down Expand Up @@ -472,7 +471,6 @@ private struct PeerEventHandler<Handler: StreamHandler>: QuicEventHandler {
metadata: ["connectionId": "\(connection.id)", "reason": "\(reason)"]
)
if shouldReconnect(basedOn: reason) {
logger.debug("shouldReconnect ", metadata: ["connectionId": "\(connection.id)"])
impl.connections.write { connections in
if let conn = connections.byId[connection.id] {
if let publicKey = conn.publicKey {
Expand Down
8 changes: 2 additions & 6 deletions Networking/Tests/NetworkingTests/PeerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ struct PeerTests {
clientSettings: .defaultSettings
)
)
try print("peer1: \(peer1.listenAddress())")
let peer2 = try Peer(
options: PeerOptions<MockStreamHandler>(
role: .validator,
Expand All @@ -283,13 +282,11 @@ struct PeerTests {
clientSettings: .defaultSettings
)
)
try print("peer2: \(peer2.listenAddress())")
try? await Task.sleep(for: .milliseconds(100))

let connection = try peer1.connect(
to: peer2.listenAddress(), role: .validator
)
print("connection addr: \(connection.remoteAddress)")
try? await Task.sleep(for: .milliseconds(100))

let receivedData = try await connection.request(
Expand All @@ -305,9 +302,8 @@ struct PeerTests {
peer1.broadcast(
kind: .uniqueC, message: .init(kind: .uniqueC, data: messageData)
)
try? await Task.sleep(for: .milliseconds(1000))
try? await Task.sleep(for: .milliseconds(5000))
let lastReceivedData = await handler2.lastReceivedData
print("lastReceivedData \(lastReceivedData?.toHexString() ?? "none")")
#expect(lastReceivedData == messageData)
}

Expand Down Expand Up @@ -421,7 +417,7 @@ struct PeerTests {
peer1.broadcast(
kind: .uniqueC, message: .init(kind: .uniqueC, data: recoverData)
)
try? await Task.sleep(for: .milliseconds(500))
try? await Task.sleep(for: .milliseconds(1000))
await #expect(handler2.lastReceivedData == recoverData)
}

Expand Down

0 comments on commit 9698005

Please sign in to comment.