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 eb7a122 commit 7124c31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
7 changes: 0 additions & 7 deletions Networking/Tests/NetworkingTests/MockPeerEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ final class MockPeerEventTests {
case shutdownInitiated(connection: QuicConnection, reason: ConnectionCloseReason)
case streamStarted(connection: QuicConnection, stream: QuicStream)
case dataReceived(stream: QuicStream, data: Data?)
case closed(stream: QuicStream, status: QuicStatus, code: QuicErrorCode)
}

let events: ThreadSafeContainer<[EventType]> = .init([])
Expand Down Expand Up @@ -80,12 +79,6 @@ final class MockPeerEventTests {
events.append(.dataReceived(stream: stream, data: data))
}
}

func closed(_ stream: QuicStream, status: QuicStatus, code: QuicErrorCode) {
events.write { events in
events.append(.closed(stream: stream, status: status, code: code))
}
}
}

let registration: QuicRegistration
Expand Down
35 changes: 7 additions & 28 deletions Networking/Tests/NetworkingTests/PeerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import Utils
@testable import Networking

struct PeerTests {
struct MockMessage: MessageProtocol {
let data: Data
func encode() throws -> Data {
data
}
}

struct MockRequest<Kind: StreamKindProtocol>: RequestProtocol {
var kind: Kind
var data: Data
Expand Down Expand Up @@ -50,10 +43,6 @@ struct PeerTests {
self.data = data
return MockRequest(kind: kind, data: data)
}

func finish() -> Data? {
data
}
}

struct MockUniqueMessageDecoder: MessageDecoder {
Expand All @@ -70,10 +59,6 @@ struct PeerTests {
self.data = data
return MockRequest(kind: kind, data: data)
}

func finish() -> Data? {
data
}
}

actor DataStorage {
Expand All @@ -89,10 +74,6 @@ struct PeerTests {
typealias Request = MockRequest<EphemeralStreamKind>
private let dataStorage: PeerTests.DataStorage = DataStorage()

var lastReceivedData: Data? {
get async { await dataStorage.data.last }
}

func createDecoder(kind: StreamKind) -> any MessageDecoder<Request> {
MockEphemeralMessageDecoder(kind: kind)
}
Expand Down Expand Up @@ -383,15 +364,13 @@ struct PeerTests {
let connection1 = try peer1.connect(to: peer2.listenAddress(), role: .validator)
let connection2 = try peer2.connect(to: peer1.listenAddress(), role: .validator)
try? await Task.sleep(for: .milliseconds(1000))
if !connection1.isClosed {
let data = try await connection1.request(MockRequest(kind: .typeA, data: Data("hello world".utf8)))
try? await Task.sleep(for: .milliseconds(500))
#expect(data == Data("hello world response".utf8))
}
if !connection2.isClosed {
let data = try await connection2.request(MockRequest(kind: .typeA, data: Data("hello world".utf8)))
try? await Task.sleep(for: .milliseconds(500))
#expect(data == Data("hello world response".utf8))
let connections = [connection1, connection2]
for connection in connections {
if !connection.isClosed {
let data = try await connection.request(MockRequest(kind: .typeA, data: Data("hello world".utf8)))
try? await Task.sleep(for: .milliseconds(500))
#expect(data == Data("hello world response".utf8))
}
}
}

Expand Down

0 comments on commit 7124c31

Please sign in to comment.