@@ -382,13 +382,11 @@ class HTTP1ConnectionTests: XCTestCase {
382
382
383
383
let lock : Lock
384
384
let backpressurePromise : EventLoopPromise < Void >
385
- let optionsApplied : EventLoopPromise < Void >
386
385
let messageReceived : EventLoopPromise < Void >
387
386
388
387
init ( eventLoop: EventLoop ) {
389
388
self . lock = Lock ( )
390
389
self . backpressurePromise = eventLoop. makePromise ( )
391
- self . optionsApplied = eventLoop. makePromise ( )
392
390
self . messageReceived = eventLoop. makePromise ( )
393
391
}
394
392
@@ -405,16 +403,7 @@ class HTTP1ConnectionTests: XCTestCase {
405
403
}
406
404
407
405
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 ( )
418
407
}
419
408
420
409
func didReceiveBodyPart( task: HTTPClient . Task < Response > , _ buffer: ByteBuffer ) -> EventLoopFuture < Void > {
@@ -434,11 +423,9 @@ class HTTP1ConnectionTests: XCTestCase {
434
423
typealias InboundIn = HTTPServerRequestPart
435
424
typealias OutboundOut = HTTPServerResponsePart
436
425
437
- let bodyFuture : EventLoopFuture < Void >
438
426
let endFuture : EventLoopFuture < Void >
439
427
440
- init ( bodyFuture: EventLoopFuture < Void > , endFuture: EventLoopFuture < Void > ) {
441
- self . bodyFuture = bodyFuture
428
+ init ( endFuture: EventLoopFuture < Void > ) {
442
429
self . endFuture = endFuture
443
430
}
444
431
@@ -451,10 +438,8 @@ class HTTP1ConnectionTests: XCTestCase {
451
438
// ignore
452
439
break
453
440
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 )
458
443
459
444
self . endFuture. hop ( to: context. eventLoop) . whenSuccess {
460
445
context. writeAndFlush ( self . wrapOutboundOut ( . end( nil ) ) , promise: nil )
@@ -473,14 +458,15 @@ class HTTP1ConnectionTests: XCTestCase {
473
458
474
459
let httpBin = HTTPBin { _ in
475
460
WriteAfterFutureSucceedsHandler (
476
- bodyFuture: backpressureDelegate. optionsApplied. futureResult,
477
461
endFuture: backpressureDelegate. backpressurePromise. futureResult
478
462
)
479
463
}
480
464
defer { XCTAssertNoThrow ( try httpBin. shutdown ( ) ) }
481
-
465
+
482
466
var maybeChannel : Channel ?
483
467
XCTAssertNoThrow ( maybeChannel = try ClientBootstrap ( group: eventLoopGroup)
468
+ . channelOption ( ChannelOptions . maxMessagesPerRead, value: 1 )
469
+ . channelOption ( ChannelOptions . recvAllocator, value: FixedSizeRecvByteBufferAllocator ( capacity: 1 ) )
484
470
. connect ( host: " localhost " , port: httpBin. port)
485
471
. wait ( ) )
486
472
guard let channel = maybeChannel else { return XCTFail ( " Expected to have a channel at this point " ) }
@@ -513,9 +499,6 @@ class HTTP1ConnectionTests: XCTestCase {
513
499
514
500
let requestFuture = requestBag. task. futureResult
515
501
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
-
519
502
// Send 4 bytes, but only one should be received until the backpressure promise is succeeded.
520
503
521
504
// Now we wait until message is delivered to client channel pipeline
0 commit comments