File tree 1 file changed +35
-0
lines changed
Tests/RediStackIntegrationTests/Commands 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,41 @@ final class RedisPubSubCommandsTests: RediStackIntegrationTestCase {
188
188
189
189
self . waitForExpectations ( timeout: 1 )
190
190
}
191
+
192
+ func test_pubSubChannels( ) throws {
193
+ let fn = #function
194
+ let subscriber = try self . makeNewConnection ( )
195
+ defer { try ? subscriber. close ( ) . wait ( ) }
196
+
197
+ let channelNames = ( 1 ... 10 ) . map {
198
+ RedisChannelName ( " \( fn) \( $0) \( $0 % 2 == 0 ? " _even " : " _odd " ) " )
199
+ }
200
+
201
+ for channelName in channelNames {
202
+ try subscriber. subscribe (
203
+ to: channelName,
204
+ messageReceiver: { _, _ in } ,
205
+ onSubscribe: nil ,
206
+ onUnsubscribe: nil
207
+ ) . wait ( )
208
+ }
209
+ XCTAssertTrue ( subscriber. isSubscribed)
210
+ defer {
211
+ // Unsubscribe (clean up)
212
+ try ? subscriber. unsubscribe ( from: channelNames) . wait ( )
213
+ XCTAssertFalse ( subscriber. isSubscribed)
214
+ }
215
+
216
+ // Make another connection to query on.
217
+ let queryConnection = try self . makeNewConnection ( )
218
+ defer { try ? queryConnection. close ( ) . wait ( ) }
219
+
220
+ let oddChannels = try queryConnection. activeChannels ( matching: " \( fn) *_odd " ) . wait ( )
221
+ XCTAssertEqual ( oddChannels. count, channelNames. count / 2 )
222
+
223
+ let allChannels = try queryConnection. activeChannels ( ) . wait ( )
224
+ XCTAssertGreaterThanOrEqual ( allChannels. count, channelNames. count)
225
+ }
191
226
}
192
227
193
228
final class RedisPubSubCommandsPoolTests : RediStackConnectionPoolIntegrationTestCase {
You can’t perform that action at this time.
0 commit comments