Skip to content

Commit 456e104

Browse files
committed
SwiftQUIC: Fix variance in Spin Bit testing
1 parent 6fb079f commit 456e104

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Sources/SwiftNetwork/QUIC/QUICConnection.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,9 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
23222322
// Reflect the spin bit.
23232323
let spinValue = packet.spinValue
23242324
path.spinValue = spinValue
2325+
if spinValue {
2326+
path.spinValueForTestingSeen = true
2327+
}
23252328
} else {
23262329
// Spin it!
23272330
let spinValue = packet.spinValue

Sources/SwiftNetwork/QUIC/QUICPath.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public final class QUICPath: MultiplexingDatagramPath<QUICConnection>, Equatable
188188
static let isFlowControlled = Flags(rawValue: 1 << 9)
189189
static let l4sEnabled = Flags(rawValue: 1 << 10)
190190
static let reportedIdleEvent = Flags(rawValue: 1 << 11)
191+
static let spinValueForTestingSeen = Flags(rawValue: 1 << 12)
191192
}
192193
private var flags = Flags()
193194

@@ -241,6 +242,10 @@ public final class QUICPath: MultiplexingDatagramPath<QUICConnection>, Equatable
241242
get { flags.contains(.reportedIdleEvent) }
242243
set { if newValue { flags.insert(.reportedIdleEvent) } else { flags.remove(.reportedIdleEvent) } }
243244
}
245+
var spinValueForTestingSeen: Bool {
246+
get { flags.contains(.spinValueForTestingSeen) }
247+
set { if newValue { flags.insert(.spinValueForTestingSeen) } else { flags.remove(.spinValueForTestingSeen) } }
248+
}
244249

245250
var log: LogPrefixer {
246251
parentProtocol.logPrefixer

Tests/SwiftNetworkTests/SwiftNetworkQUICSpinBitTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ final class SwiftNetworkQUICSpinBitTests: NetTestCase {
9191
defer { expectation.fulfill() }
9292

9393
let clientSpinBit = harness.state?.clientInstance.currentPath?.spinValue ?? false
94-
let serverSpinBit = harness.state?.serverInstance.currentPath?.spinValue ?? false
94+
// Note that spinValueForTestingSeen is checked here because it could be that by the time
95+
// this test checks the server spin bit value it has received the ACK from the client and the
96+
// spin bit value has already changed. This reliably make sure that the spin bit on the server was present.
97+
let serverSpinBit = harness.state?.serverInstance.currentPath?.spinValueForTestingSeen ?? false
9598
XCTAssertFalse(clientSpinBit, "Client should have the spin bit set to false")
9699
XCTAssertTrue(serverSpinBit, "Server should have the spin bit set to true")
97100
}

0 commit comments

Comments
 (0)