Skip to content

Commit

Permalink
update coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Nov 26, 2024
1 parent 731c79b commit 11d0d50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
7 changes: 2 additions & 5 deletions Networking/Sources/Networking/Peer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private struct PeerEventHandler<Handler: StreamHandler>: QuicEventHandler {
)
return
}
// Check if the connection is already reconnected

impl.reconnectStates.write { reconnectStates in
reconnectStates[conn.remoteAddress] = nil
}
Expand Down Expand Up @@ -528,10 +528,7 @@ private struct PeerEventHandler<Handler: StreamHandler>: QuicEventHandler {
}

func shutdownInitiated(_ connection: QuicConnection, reason: ConnectionCloseReason) {
logger.debug(
"Shutdown initiated",
metadata: ["connectionId": "\(connection.id)", "reason": "\(reason)"]
)
logger.debug("Shutdown initiated", metadata: ["connectionId": "\(connection.id)", "reason": "\(reason)"])
if shouldReconnect(basedOn: reason) {
impl.connections.write { connections in
if let conn = connections.byId[connection.id] {
Expand Down
26 changes: 18 additions & 8 deletions Networking/Tests/NetworkingTests/PeerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ struct PeerTests {

let connection1 = try peer1.connect(to: listenAddress, role: .validator)
try? await Task.sleep(for: .milliseconds(3000))
#expect(throws: Error.self) {
_ = try connection1.createStream(kind: .typeA)
}
#expect(throws: Error.self) {
_ = try connection1.createStream(kind: .uniqueA)
}
#expect(connection1.isClosed == true)
}

Expand Down Expand Up @@ -429,7 +435,7 @@ struct PeerTests {
let handler1 = MockPresentStreamHandler()
let handler2 = MockPresentStreamHandler()
// Define the data size, 5MB
let dataSize = 5 * 1024 * 1024
let dataSize = 10 * 1024 * 1024
var largeData = Data(capacity: dataSize)

// Generate random data
Expand Down Expand Up @@ -471,25 +477,29 @@ struct PeerTests {
try? await Task.sleep(for: .milliseconds(50))

let receivedData1 = try await connection1.request(
MockRequest(kind: .typeA, data: largeData)
MockRequest(kind: .typeA, data: largeData.prefix(dataSize / 2))
)
try? await Task.sleep(for: .milliseconds(100))

// Verify that the received data matches the original large data
#expect(receivedData1 == largeData + Data(" response".utf8))

#expect(receivedData1 == largeData.prefix(dataSize / 2) + Data(" response".utf8))
peer1.broadcast(
kind: .uniqueA, message: .init(kind: .uniqueA, data: largeData)
kind: .uniqueA, message: .init(kind: .uniqueA, data: largeData.prefix(dataSize / 2))
)
try? await Task.sleep(for: .milliseconds(100))

peer2.broadcast(
kind: .uniqueB, message: .init(kind: .uniqueB, data: largeData)
kind: .uniqueB, message: .init(kind: .uniqueB, data: largeData.prefix(dataSize / 2))
)
// Verify last received data
try? await Task.sleep(for: .milliseconds(2000))
await #expect(handler2.lastReceivedData == largeData)
await #expect(handler1.lastReceivedData == largeData)
await #expect(handler2.lastReceivedData == largeData.prefix(dataSize / 2))
await #expect(handler1.lastReceivedData == largeData.prefix(dataSize / 2))
await #expect(throws: Error.self) {
_ = try await connection1.request(
MockRequest(kind: .typeC, data: largeData)
)
}
}

@Test
Expand Down

0 comments on commit 11d0d50

Please sign in to comment.