Skip to content

Commit 202f987

Browse files
glbrnttrnro
andauthored
Strict concurrency for NIOHTTP1Tests (#3169)
Co-authored-by: Rick Newton-Rogers <[email protected]>
1 parent 350794f commit 202f987

10 files changed

+416
-277
lines changed

Package.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ let package = Package(
498498
"NIOHTTP1",
499499
"NIOFoundationCompat",
500500
"NIOTestUtils",
501-
]
501+
],
502+
swiftSettings: strictConcurrencySettings
502503
),
503504
.testTarget(
504505
name: "NIOTLSTests",

Tests/NIOHTTP1Tests/HTTPClientUpgradeTests.swift

+160-81
Large diffs are not rendered by default.

Tests/NIOHTTP1Tests/HTTPDecoderLengthTest.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class HTTPDecoderLengthTest: XCTestCase {
125125
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPResponseDecoder())))
126126

127127
let handler = ChannelInactiveHandler(eofMechanism)
128-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
128+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
129129

130130
// Prime the decoder with a GET and consume it.
131131
XCTAssertTrue(
@@ -197,7 +197,7 @@ class HTTPDecoderLengthTest: XCTestCase {
197197
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(decoder)))
198198

199199
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
200-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
200+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
201201

202202
// Prime the decoder with a request and consume it.
203203
XCTAssertTrue(
@@ -351,7 +351,7 @@ class HTTPDecoderLengthTest: XCTestCase {
351351
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPRequestDecoder())))
352352

353353
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
354-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
354+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
355355

356356
// Send a GET with the appropriate Transfer Encoding header.
357357
XCTAssertThrowsError(
@@ -369,7 +369,7 @@ class HTTPDecoderLengthTest: XCTestCase {
369369
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPRequestDecoder())))
370370

371371
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
372-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
372+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
373373

374374
// Send a GET with the appropriate Transfer Encoding header.
375375
XCTAssertNoThrow(
@@ -402,7 +402,7 @@ class HTTPDecoderLengthTest: XCTestCase {
402402
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPResponseDecoder())))
403403

404404
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
405-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
405+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
406406

407407
// Prime the decoder with a request and consume it.
408408
XCTAssertTrue(
@@ -458,7 +458,7 @@ class HTTPDecoderLengthTest: XCTestCase {
458458
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPResponseDecoder())))
459459

460460
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
461-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
461+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
462462

463463
// Prime the decoder with a request and consume it.
464464
XCTAssertTrue(
@@ -665,7 +665,7 @@ class HTTPDecoderLengthTest: XCTestCase {
665665
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(HTTPRequestDecoder())))
666666

667667
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
668-
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
668+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(handler))
669669

670670
// Send a POST without a length field of any kind. This should be a zero-length request,
671671
// so .end should come immediately.

Tests/NIOHTTP1Tests/HTTPDecoderTest.swift

+11-9
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class HTTPDecoderTest: XCTestCase {
202202
name: "decoder"
203203
)
204204
)
205-
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
205+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(Receiver()))
206206

207207
var buffer = channel.allocator.buffer(capacity: 64)
208208
buffer.writeStaticString(
@@ -251,8 +251,9 @@ class HTTPDecoderTest: XCTestCase {
251251
let part = Self.unwrapInboundIn(data)
252252
switch part {
253253
case .end:
254-
_ = context.pipeline.removeHandler(self).flatMap { [pipeline = context.pipeline] _ in
255-
pipeline.addHandler(self.collector)
254+
_ = context.pipeline.syncOperations.removeHandler(self).assumeIsolated().flatMapThrowing {
255+
[pipeline = context.pipeline] _ in
256+
try pipeline.syncOperations.addHandler(self.collector)
256257
}
257258
default:
258259
// ignore
@@ -266,7 +267,7 @@ class HTTPDecoderTest: XCTestCase {
266267
name: "decoder"
267268
)
268269
)
269-
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
270+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(Receiver()))
270271

271272
// This connect call is semantically wrong, but it's how you
272273
// active embedded channels properly right now.
@@ -324,8 +325,9 @@ class HTTPDecoderTest: XCTestCase {
324325
let part = Self.unwrapInboundIn(data)
325326
switch part {
326327
case .end:
327-
_ = context.pipeline.removeHandler(self).flatMap { [pipeline = context.pipeline] _ in
328-
pipeline.addHandler(ByteCollector())
328+
_ = context.pipeline.syncOperations.removeHandler(self).assumeIsolated().flatMapThrowing {
329+
[pipeline = context.pipeline] _ in
330+
try pipeline.syncOperations.addHandler(ByteCollector())
329331
}
330332
break
331333
default:
@@ -341,7 +343,7 @@ class HTTPDecoderTest: XCTestCase {
341343
name: "decoder"
342344
)
343345
)
344-
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
346+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(Receiver()))
345347

346348
XCTAssertNoThrow(try channel.connect(to: SocketAddress(ipAddress: "127.0.0.1", port: 8888)).wait())
347349

@@ -665,7 +667,7 @@ class HTTPDecoderTest: XCTestCase {
665667

666668
let decoder = HTTPRequestDecoder(leftOverBytesStrategy: leftOverBytesStrategy)
667669
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(decoder)))
668-
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
670+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(Receiver()))
669671
XCTAssertNoThrow(try channel.writeInbound(buffer))
670672
XCTAssertNoThrow(XCTAssert(try channel.finish().isClean))
671673
}
@@ -695,7 +697,7 @@ class HTTPDecoderTest: XCTestCase {
695697
let receiver = Receiver()
696698
let decoder = ByteToMessageHandler(HTTPRequestDecoder(leftOverBytesStrategy: .forwardBytes))
697699
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(decoder))
698-
XCTAssertNoThrow(try channel.pipeline.addHandler(receiver).wait())
700+
XCTAssertNoThrow(try channel.pipeline.syncOperations.addHandler(receiver))
699701
XCTAssertNoThrow(try channel.writeInbound(buffer))
700702
let removalFutures = [
701703
channel.pipeline.syncOperations.removeHandler(receiver),

0 commit comments

Comments
 (0)