File tree Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -446,9 +446,16 @@ public final class ChannelPipeline: ChannelInvoker {
446
446
return promise. futureResult
447
447
}
448
448
449
+ /// Returns a `ChannelHandlerContext` which matches.
450
+ ///
451
+ /// This skips head and tail (as these are internal and should not be accessible by the user.
452
+ ///
453
+ /// - parameters:
454
+ /// - body: The predicate to execute per `ChannelHandlerContext` in the `ChannelPipeline`.
455
+ /// -returns: The `ChannelHandlerContext` that matches or `nil` if non did.
449
456
private func contextForPredicate0( _ body: @escaping ( ( ChannelHandlerContext ) -> Bool ) ) -> ChannelHandlerContext ? {
450
- var curCtx : ChannelHandlerContext ? = self . head
451
- while let ctx = curCtx {
457
+ var curCtx : ChannelHandlerContext ? = self . head? . next
458
+ while let ctx = curCtx, ctx !== self . tail {
452
459
if body ( ctx) {
453
460
return ctx
454
461
}
@@ -1422,8 +1429,8 @@ public final class ChannelHandlerContext: ChannelInvoker {
1422
1429
extension ChannelPipeline : CustomDebugStringConvertible {
1423
1430
public var debugDescription : String {
1424
1431
var desc = " ChannelPipeline ( \( ObjectIdentifier ( self ) ) ): \n "
1425
- var node = self . head
1426
- while let ctx = node {
1432
+ var node = self . head? . next
1433
+ while let ctx = node, ctx !== self . tail {
1427
1434
let inboundStr = ctx. handler is _ChannelInboundHandler ? " I " : " "
1428
1435
let outboundStr = ctx. handler is _ChannelOutboundHandler ? " O " : " "
1429
1436
desc += " \( ctx. name) ( \( type ( of: ctx. handler) ) ) [ \( inboundStr) \( outboundStr) ] \n "
Original file line number Diff line number Diff line change @@ -620,4 +620,48 @@ class ChannelPipelineTest: XCTestCase {
620
620
XCTAssertTrue ( try h1 === channel. pipeline. context ( handlerType: TestHandler . self) . wait ( ) . handler)
621
621
XCTAssertFalse ( try h2 === channel. pipeline. context ( handlerType: TestHandler . self) . wait ( ) . handler)
622
622
}
623
+
624
+ func testContextForHeadOrTail( ) throws {
625
+ let channel = EmbeddedChannel ( )
626
+
627
+ defer {
628
+ XCTAssertFalse ( try channel. finish ( ) )
629
+ }
630
+
631
+ do {
632
+ _ = try channel. pipeline. context ( name: " head " ) . wait ( )
633
+ XCTFail ( )
634
+ } catch let err as ChannelPipelineError where err == . notFound {
635
+ /// expected
636
+ }
637
+
638
+ do {
639
+ _ = try channel. pipeline. context ( name: " tail " ) . wait ( )
640
+ XCTFail ( )
641
+ } catch let err as ChannelPipelineError where err == . notFound {
642
+ /// expected
643
+ }
644
+ }
645
+
646
+ func testRemoveHeadOrTail( ) throws {
647
+ let channel = EmbeddedChannel ( )
648
+
649
+ defer {
650
+ XCTAssertFalse ( try channel. finish ( ) )
651
+ }
652
+
653
+ do {
654
+ _ = try channel. pipeline. remove ( name: " head " ) . wait ( )
655
+ XCTFail ( )
656
+ } catch let err as ChannelPipelineError where err == . notFound {
657
+ /// expected
658
+ }
659
+
660
+ do {
661
+ _ = try channel. pipeline. remove ( name: " tail " ) . wait ( )
662
+ XCTFail ( )
663
+ } catch let err as ChannelPipelineError where err == . notFound {
664
+ /// expected
665
+ }
666
+ }
623
667
}
You can’t perform that action at this time.
0 commit comments