Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reconnect attempt #216

Merged
merged 14 commits into from
Nov 5, 2024
34 changes: 20 additions & 14 deletions Networking/Tests/NetworkingTests/MockPeerEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ final class MockPeerEventTests {
configuration: clientConfiguration
)

// Attempt to connect
try clientConnection.connect(to: listenAddress)
let stream1 = try clientConnection.createStream()
try stream1.send(data: Data("test data 1".utf8))
do {
try clientConnection.connect(to: listenAddress)
let stream1 = try clientConnection.createStream()
try stream1.send(data: Data("test data 1".utf8))
} catch {
#expect(error != nil)
MacOMNI marked this conversation as resolved.
Show resolved Hide resolved
return
}

try? await Task.sleep(for: .milliseconds(100))
try await Task.sleep(for: .milliseconds(100))
let (_, reason) = clientHandler.events.value.compactMap {
switch $0 {
case let .shutdownInitiated(connection, reason):
Expand Down Expand Up @@ -212,7 +216,7 @@ final class MockPeerEventTests {
let stream1 = try clientConnection.createStream()
try stream1.send(data: Data("test data 1".utf8))

try? await Task.sleep(for: .milliseconds(100))
try await Task.sleep(for: .milliseconds(100))
let (_, info) = serverHandler.events.value.compactMap {
switch $0 {
case let .newConnection(_, connection, info):
Expand Down Expand Up @@ -266,14 +270,16 @@ final class MockPeerEventTests {
registration: registration,
configuration: clientConfiguration
)

// Attempt to connect
try clientConnection.connect(to: listenAddress)
let stream1 = try clientConnection.createStream()
try stream1.send(data: Data("test data 1".utf8))

try? await Task.sleep(for: .milliseconds(100))
let (_, reason) = serverHandler.events.value.compactMap {
do {
try clientConnection.connect(to: listenAddress)
let stream1 = try clientConnection.createStream()
try stream1.send(data: Data("test data 1".utf8))
} catch {
#expect(error != nil)
return
}
try await Task.sleep(for: .milliseconds(100))
let (_, reason) = clientHandler.events.value.compactMap {
switch $0 {
case let .shutdownInitiated(connection, reason):
(connection, reason) as (QuicConnection, ConnectionCloseReason)?
Expand Down
7 changes: 2 additions & 5 deletions Networking/Tests/NetworkingTests/PeerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,9 @@ struct PeerTests {
}

var connections = [Connection<MockStreamHandler>]()
for i in 0 ..< peers.count {
for i in 0 ..< peersCount {
let peer = peers[i]
for j in 0 ..< peers.count {
if i >= j {
continue
}
for j in i + 1 ..< peersCount {
let otherPeer = peers[j]
let conn = try peer.connect(
to: otherPeer.listenAddress(),
Expand Down