@@ -231,6 +231,42 @@ final class RedisPubSubCommandsTests: RediStackIntegrationTestCase {
231
231
let allChannels = try queryConnection. activeChannels ( ) . wait ( )
232
232
XCTAssertGreaterThanOrEqual ( allChannels. count, channelNames. count)
233
233
}
234
+
235
+ func test_pubSubNumsub( ) throws {
236
+ let fn = #function
237
+ let subscriber = try self . makeNewConnection ( )
238
+ defer { try ? subscriber. close ( ) . wait ( ) }
239
+
240
+ let channelNames = ( 1 ... 5 ) . map {
241
+ RedisChannelName ( " \( fn) \( $0) " )
242
+ }
243
+
244
+ for channelName in channelNames {
245
+ try subscriber. subscribe (
246
+ to: channelName,
247
+ messageReceiver: { _, _ in } ,
248
+ onSubscribe: nil ,
249
+ onUnsubscribe: nil
250
+ ) . wait ( )
251
+ }
252
+ XCTAssertTrue ( subscriber. isSubscribed)
253
+ defer {
254
+ // Unsubscribe (clean up)
255
+ try ? subscriber. unsubscribe ( from: channelNames) . wait ( )
256
+ XCTAssertFalse ( subscriber. isSubscribed)
257
+ }
258
+
259
+ // Make another connection to query on.
260
+ let queryConnection = try self . makeNewConnection ( )
261
+ defer { try ? queryConnection. close ( ) . wait ( ) }
262
+
263
+ let notSubscribedChannel = RedisChannelName ( " \( fn) _notsubbed " )
264
+ let numSubs = try queryConnection. subscriberCount ( forChannels: [ channelNames [ 0 ] , notSubscribedChannel] ) . wait ( )
265
+ XCTAssertEqual ( numSubs. count, 2 )
266
+
267
+ XCTAssertGreaterThanOrEqual ( numSubs [ channelNames [ 0 ] ] ?? 0 , 1 )
268
+ XCTAssertEqual ( numSubs [ notSubscribedChannel] , 0 )
269
+ }
234
270
}
235
271
236
272
final class RedisPubSubCommandsPoolTests : RediStackConnectionPoolIntegrationTestCase {
0 commit comments