File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,8 @@ private final class CollectAcceptedChannelsHandler: ChannelInboundHandler {
216
216
/// try fullyShutdownPromise.futureResult.wait()
217
217
///
218
218
public final class ServerQuiescingHelper {
219
+ /// The `ServerQuiescingHelper` was never used to create a channel handler.
220
+ public struct UnusedQuiescingHelperError : Error { }
219
221
private let channelCollectorPromise : EventLoopPromise < ChannelCollector >
220
222
221
223
/// Initialize with a given `EventLoopGroup`.
@@ -226,6 +228,10 @@ public final class ServerQuiescingHelper {
226
228
self . channelCollectorPromise = group. next ( ) . makePromise ( )
227
229
}
228
230
231
+ deinit {
232
+ self . channelCollectorPromise. fail ( UnusedQuiescingHelperError ( ) )
233
+ }
234
+
229
235
/// Create the `ChannelHandler` for the server `channel` to collect all accepted child `Channel`s.
230
236
///
231
237
/// - parameters:
Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the SwiftNIO open source project
4
4
//
5
- // Copyright (c) 2018-2022 Apple Inc. and the SwiftNIO project authors
5
+ // Copyright (c) 2018-2023 Apple Inc. and the SwiftNIO project authors
6
6
// Licensed under Apache License v2.0
7
7
//
8
8
// See LICENSE.txt for license information
@@ -30,6 +30,7 @@ extension QuiescingHelperTest {
30
30
( " testShutdownIsImmediateWhenNoChannelsCollected " , testShutdownIsImmediateWhenNoChannelsCollected) ,
31
31
( " testQuiesceUserEventReceivedOnShutdown " , testQuiesceUserEventReceivedOnShutdown) ,
32
32
( " testQuiescingDoesNotSwallowCloseErrorsFromAcceptHandler " , testQuiescingDoesNotSwallowCloseErrorsFromAcceptHandler) ,
33
+ ( " testShutdownIsImmediateWhenPromiseDoesNotSucceed " , testShutdownIsImmediateWhenPromiseDoesNotSucceed) ,
33
34
]
34
35
}
35
36
}
Original file line number Diff line number Diff line change @@ -136,4 +136,19 @@ public class QuiescingHelperTest: XCTestCase {
136
136
XCTAssert ( error is DummyError )
137
137
}
138
138
}
139
+
140
+ ///verifying that the promise fails when goes out of scope for shutdown
141
+ func testShutdownIsImmediateWhenPromiseDoesNotSucceed( ) throws {
142
+ let el = EmbeddedEventLoop ( )
143
+
144
+ let p : EventLoopPromise < Void > = el. makePromise ( )
145
+
146
+ do {
147
+ let quiesce = ServerQuiescingHelper ( group: el)
148
+ quiesce. initiateShutdown ( promise: p)
149
+ }
150
+ XCTAssertThrowsError ( try p. futureResult. wait ( ) ) { error in
151
+ XCTAssertTrue ( error is ServerQuiescingHelper . UnusedQuiescingHelperError )
152
+ }
153
+ }
139
154
}
You can’t perform that action at this time.
0 commit comments