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