Skip to content

Commit 4653c80

Browse files
committed
Make test easier.
1 parent 2ba57d7 commit 4653c80

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTP1ConnectionTests.swift

+6-23
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,11 @@ class HTTP1ConnectionTests: XCTestCase {
382382

383383
let lock: Lock
384384
let backpressurePromise: EventLoopPromise<Void>
385-
let optionsApplied: EventLoopPromise<Void>
386385
let messageReceived: EventLoopPromise<Void>
387386

388387
init(eventLoop: EventLoop) {
389388
self.lock = Lock()
390389
self.backpressurePromise = eventLoop.makePromise()
391-
self.optionsApplied = eventLoop.makePromise()
392390
self.messageReceived = eventLoop.makePromise()
393391
}
394392

@@ -405,16 +403,7 @@ class HTTP1ConnectionTests: XCTestCase {
405403
}
406404

407405
func didReceiveHead(task: HTTPClient.Task<Void>, _ head: HTTPResponseHead) -> EventLoopFuture<Void> {
408-
// This is to force NIO to send only 1 byte at a time.
409-
guard let channel = self.lock.withLock({ self._channel }) else {
410-
preconditionFailure("Expected to have a channel at this point")
411-
}
412-
413-
let future = channel.setOption(ChannelOptions.maxMessagesPerRead, value: 1).flatMap {
414-
channel.setOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 1))
415-
}
416-
future.cascade(to: self.optionsApplied)
417-
return future
406+
return task.futureResult.eventLoop.makeSucceededVoidFuture()
418407
}
419408

420409
func didReceiveBodyPart(task: HTTPClient.Task<Response>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
@@ -434,11 +423,9 @@ class HTTP1ConnectionTests: XCTestCase {
434423
typealias InboundIn = HTTPServerRequestPart
435424
typealias OutboundOut = HTTPServerResponsePart
436425

437-
let bodyFuture: EventLoopFuture<Void>
438426
let endFuture: EventLoopFuture<Void>
439427

440-
init(bodyFuture: EventLoopFuture<Void>, endFuture: EventLoopFuture<Void>) {
441-
self.bodyFuture = bodyFuture
428+
init(endFuture: EventLoopFuture<Void>) {
442429
self.endFuture = endFuture
443430
}
444431

@@ -451,10 +438,8 @@ class HTTP1ConnectionTests: XCTestCase {
451438
// ignore
452439
break
453440
case .end:
454-
self.bodyFuture.hop(to: context.eventLoop).whenSuccess {
455-
let buffer = context.channel.allocator.buffer(string: "1234")
456-
context.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
457-
}
441+
let buffer = context.channel.allocator.buffer(string: "1234")
442+
context.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil)
458443

459444
self.endFuture.hop(to: context.eventLoop).whenSuccess {
460445
context.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
@@ -473,14 +458,15 @@ class HTTP1ConnectionTests: XCTestCase {
473458

474459
let httpBin = HTTPBin { _ in
475460
WriteAfterFutureSucceedsHandler(
476-
bodyFuture: backpressureDelegate.optionsApplied.futureResult,
477461
endFuture: backpressureDelegate.backpressurePromise.futureResult
478462
)
479463
}
480464
defer { XCTAssertNoThrow(try httpBin.shutdown()) }
481465

482466
var maybeChannel: Channel?
483467
XCTAssertNoThrow(maybeChannel = try ClientBootstrap(group: eventLoopGroup)
468+
.channelOption(ChannelOptions.maxMessagesPerRead, value: 1)
469+
.channelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 1))
484470
.connect(host: "localhost", port: httpBin.port)
485471
.wait())
486472
guard let channel = maybeChannel else { return XCTFail("Expected to have a channel at this point") }
@@ -513,9 +499,6 @@ class HTTP1ConnectionTests: XCTestCase {
513499

514500
let requestFuture = requestBag.task.futureResult
515501

516-
// We need to wait for channel options that limit NIO to sending only one byte at a time.
517-
XCTAssertNoThrow(try backpressureDelegate.optionsApplied.futureResult.wait())
518-
519502
// Send 4 bytes, but only one should be received until the backpressure promise is succeeded.
520503

521504
// Now we wait until message is delivered to client channel pipeline

0 commit comments

Comments
 (0)