Skip to content

Commit f2bbfc5

Browse files
committed
PR changes
1 parent cb80840 commit f2bbfc5

8 files changed

+80
-29
lines changed

Sources/NIOHTTP2/HTTP2StreamChannel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore, @unchecked Sendable {
694694
self.failPendingWrites(error: error)
695695
if let promise = self.pendingClosePromise {
696696
self.pendingClosePromise = nil
697-
promise.succeed()
697+
promise.fail(error)
698698
}
699699
self.pipeline.fireErrorCaught(error)
700700
self.pipeline.fireChannelInactive()

Tests/NIOHTTP2Tests/ConfiguringPipelineInlineMultiplexerTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ class ConfiguringPipelineInlineMultiplexerTests: XCTestCase {
8787

8888
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
8989
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
90-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
90+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
91+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
92+
}
9193
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
9294

9395
// We should have received a HEADERS and a RST_STREAM frame.
@@ -153,7 +155,9 @@ class ConfiguringPipelineInlineMultiplexerTests: XCTestCase {
153155

154156
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
155157
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
156-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
158+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
159+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
160+
}
157161
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
158162

159163
// We should have received a HEADERS and a RST_STREAM frame.
@@ -490,7 +494,9 @@ class ConfiguringPipelineInlineMultiplexerTests: XCTestCase {
490494

491495
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
492496
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
493-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
497+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
498+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
499+
}
494500
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
495501

496502
// Assert that the user-provided handler received the
@@ -585,7 +591,9 @@ class ConfiguringPipelineInlineMultiplexerTests: XCTestCase {
585591

586592
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
587593
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
588-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
594+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
595+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
596+
}
589597
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
590598

591599
// Assert that the user-provided handler received the

Tests/NIOHTTP2Tests/ConfiguringPipelineTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ class ConfiguringPipelineTests: XCTestCase {
7878

7979
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
8080
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
81-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
81+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
82+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
83+
}
8284
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
8385

8486
// We should have received a HEADERS and a RST_STREAM frame.
@@ -137,7 +139,9 @@ class ConfiguringPipelineTests: XCTestCase {
137139

138140
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
139141
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
140-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
142+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
143+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
144+
}
141145
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
142146

143147
// We should have received a HEADERS and a RST_STREAM frame.
@@ -428,7 +432,9 @@ class ConfiguringPipelineTests: XCTestCase {
428432

429433
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
430434
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
431-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
435+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
436+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
437+
}
432438
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
433439

434440
let serverChildChannel = try serverChildChannelPromise.futureResult.wait()
@@ -522,7 +528,9 @@ class ConfiguringPipelineTests: XCTestCase {
522528

523529
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
524530
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
525-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
531+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
532+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
533+
}
526534
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
527535

528536
let serverChildChannel = try serverChildChannelPromise.futureResult.wait()

Tests/NIOHTTP2Tests/ConfiguringPipelineWithFramePayloadStreamsTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class ConfiguringPipelineWithFramePayloadStreamsTests: XCTestCase {
9191

9292
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
9393
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
94-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
94+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
95+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
96+
}
9597
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
9698

9799
// We should have received a HEADERS and a RST_STREAM frame.
@@ -152,7 +154,9 @@ class ConfiguringPipelineWithFramePayloadStreamsTests: XCTestCase {
152154

153155
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
154156
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
155-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
157+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
158+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
159+
}
156160
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
157161

158162
// We should have received a HEADERS and a RST_STREAM frame.
@@ -466,7 +470,9 @@ class ConfiguringPipelineWithFramePayloadStreamsTests: XCTestCase {
466470

467471
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
468472
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
469-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
473+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
474+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
475+
}
470476
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
471477

472478
// Assert that the user-provided handler received the
@@ -557,7 +563,9 @@ class ConfiguringPipelineWithFramePayloadStreamsTests: XCTestCase {
557563

558564
let streamChannel = try XCTUnwrap(streamChannelPromise.futureResult.wait())
559565
XCTAssertNoThrow(try streamChannel.closeFuture.wait())
560-
XCTAssertNoThrow(try requestPromise.futureResult.wait())
566+
XCTAssertThrowsError(try requestPromise.futureResult.wait()) { error in
567+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
568+
}
561569
XCTAssertTrue(errorHandler.encounteredError is NIOHTTP2Errors.StreamClosed)
562570

563571
// Assert that the user-provided handler received the

Tests/NIOHTTP2Tests/HTTP2FramePayloadStreamMultiplexerTests.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
165165
let rstStreamFrame = HTTP2Frame(streamID: streamID, payload: .rstStream(.cancel))
166166

167167
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { channel in
168-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
168+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
169169
XCTAssertNil(errorEncounteredHandler.encounteredError)
170170
channel.closeFuture.whenSuccess {
171171
streamChannelClosed.withLockedValue { $0 = true }
@@ -214,7 +214,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
214214
)
215215

216216
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { channel in
217-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
217+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
218218
XCTAssertNil(errorEncounteredHandler.encounteredError)
219219
channel.closeFuture.whenSuccess {
220220
streamChannelClosed.withLockedValue { $0 = true }
@@ -445,7 +445,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
445445
let channelPromise: EventLoopPromise<Channel> = self.channel.eventLoop.makePromise()
446446
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { channel in
447447
channelPromise.succeed(channel)
448-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
448+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
449449
return channel.eventLoop.makeSucceededFuture(())
450450
}
451451
XCTAssertNoThrow(try self.channel.pipeline.addHandler(frameReceiver).wait())
@@ -464,10 +464,19 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
464464
XCTAssertTrue(childChannel.isActive)
465465

466466
// Now we close it. This triggers a RST_STREAM frame.
467-
// Also make sure the close promise is not failed: closing still succeeds.
468-
childChannel.close().whenFailure { error in
467+
// Make sure the closeFuture is not failed (closing still succeeds).
468+
// The promise from calling close() should fail to provide the caller with diagnostics.
469+
childChannel.closeFuture.whenFailure { _ in
469470
XCTFail("The close promise should not be failed.")
470471
}
472+
childChannel.close().whenComplete { result in
473+
switch result {
474+
case .success:
475+
XCTFail("The close promise should have been failed.")
476+
case .failure(let error):
477+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
478+
}
479+
}
471480
XCTAssertEqual(frameReceiver.flushedWrites.count, 1)
472481
frameReceiver.flushedWrites[0].assertRstStreamFrame(streamID: streamID, errorCode: .cancel)
473482
XCTAssertNil(errorEncounteredHandler.encounteredError)

Tests/NIOHTTP2Tests/HTTP2InlineStreamMultiplexerTests.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ final class HTTP2InlineStreamMultiplexerTests: XCTestCase {
240240
mode: .server,
241241
eventLoop: self.channel.eventLoop,
242242
inboundStreamInitializer: { channel in
243-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
243+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
244244
XCTAssertNil(errorEncounteredHandler.encounteredError)
245245
channel.closeFuture.whenSuccess {
246246
streamChannelClosed.withLockedValue { $0 = true }
@@ -301,7 +301,7 @@ final class HTTP2InlineStreamMultiplexerTests: XCTestCase {
301301
// Let's open the stream up.
302302
let multiplexer = try http2Handler.multiplexer.wait()
303303
let streamFuture = multiplexer.createStreamChannel { channel in
304-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
304+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
305305
XCTAssertNil(errorEncounteredHandler.encounteredError)
306306
channel.closeFuture.whenSuccess {
307307
streamChannelClosed.withLockedValue { $0 = true }
@@ -530,7 +530,7 @@ final class HTTP2InlineStreamMultiplexerTests: XCTestCase {
530530
eventLoop: self.channel.eventLoop,
531531
inboundStreamInitializer: { channel in
532532
channelPromise.succeed(channel)
533-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
533+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
534534
return channel.eventLoop.makeSucceededVoidFuture()
535535
}
536536
)
@@ -549,10 +549,19 @@ final class HTTP2InlineStreamMultiplexerTests: XCTestCase {
549549
XCTAssertTrue(childChannel.isActive)
550550

551551
// Now we close it. This triggers a RST_STREAM frame.
552-
// Also make sure the close promise is not failed: closing still succeeds.
553-
childChannel.close().whenFailure { error in
552+
// Make sure the closeFuture is not failed (closing still succeeds).
553+
// The promise from calling close() should fail to provide the caller with diagnostics.
554+
childChannel.closeFuture.whenFailure { _ in
554555
XCTFail("The close promise should not be failed.")
555556
}
557+
childChannel.close().whenComplete { result in
558+
switch result {
559+
case .success:
560+
XCTFail("The close promise should have been failed.")
561+
case .failure(let error):
562+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
563+
}
564+
}
556565
XCTAssertEqual(frameReceiver.flushedWrites.count, 1)
557566

558567
var frameDecoder = HTTP2FrameDecoder(

Tests/NIOHTTP2Tests/HTTP2StreamMultiplexerTests.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
342342
let rstStreamFrame = HTTP2Frame(streamID: streamID, payload: .rstStream(.cancel))
343343

344344
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { (channel, _) in
345-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
345+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
346346
XCTAssertNil(errorEncounteredHandler.encounteredError)
347347
channel.closeFuture.whenSuccess {
348348
streamChannelClosed.withLockedValue { $0 = true }
@@ -390,7 +390,7 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
390390
)
391391

392392
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { (channel, _) in
393-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
393+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
394394
XCTAssertNil(errorEncounteredHandler.encounteredError)
395395
channel.closeFuture.whenSuccess {
396396
streamChannelClosed.withLockedValue { $0 = true }
@@ -628,7 +628,7 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
628628
let channelPromise: EventLoopPromise<Channel> = self.channel.eventLoop.makePromise()
629629
let multiplexer = HTTP2StreamMultiplexer(mode: .server, channel: self.channel) { (channel, _) in
630630
channelPromise.succeed(channel)
631-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
631+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
632632
return channel.eventLoop.makeSucceededFuture(())
633633
}
634634
XCTAssertNoThrow(try self.channel.pipeline.addHandler(frameReceiver).wait())
@@ -647,10 +647,19 @@ final class HTTP2StreamMultiplexerTests: XCTestCase {
647647
XCTAssertTrue(childChannel.isActive)
648648

649649
// Now we close it. This triggers a RST_STREAM frame.
650-
// Also make sure the close promise is not failed: closing still succeeds.
651-
childChannel.close().whenFailure { error in
650+
// Make sure the closeFuture is not failed (closing still succeeds).
651+
// The promise from calling close() should fail to provide the caller with diagnostics.
652+
childChannel.closeFuture.whenFailure { _ in
652653
XCTFail("The close promise should not be failed.")
653654
}
655+
childChannel.close().whenComplete { result in
656+
switch result {
657+
case .success:
658+
XCTFail("The close promise should have been failed.")
659+
case .failure(let error):
660+
XCTAssertTrue(error is NIOHTTP2Errors.StreamClosed)
661+
}
662+
}
654663
XCTAssertEqual(frameReceiver.flushedWrites.count, 1)
655664
frameReceiver.flushedWrites[0].assertRstStreamFrame(streamID: streamID, errorCode: .cancel)
656665
XCTAssertNil(errorEncounteredHandler.encounteredError)

Tests/NIOHTTP2Tests/SimpleClientServerInlineStreamMultiplexerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class SimpleClientServerInlineStreamMultiplexerTests: XCTestCase {
381381
let childChannelPromise = self.clientChannel.eventLoop.makePromise(of: Channel.self)
382382
let multiplexer = try self.clientChannel.pipeline.handler(type: NIOHTTP2Handler.self).wait().multiplexer.wait()
383383
multiplexer.createStreamChannel(promise: childChannelPromise) { channel in
384-
try? channel.pipeline.addHandler(errorEncounteredHandler).wait()
384+
try? channel.pipeline.syncOperations.addHandler(errorEncounteredHandler)
385385
return channel.pipeline.addHandler(clientHandler)
386386
}
387387
self.clientChannel.embeddedEventLoop.run()

0 commit comments

Comments
 (0)