@@ -455,6 +455,30 @@ struct GeneratedCommands {
455
455
}
456
456
}
457
457
458
+ @Test
459
+ @available ( valkeySwift 1 . 0 , * )
460
+ func testCancelSubscription( ) async throws {
461
+ let ( stream, cont) = AsyncStream . makeStream ( of: Void . self)
462
+ var logger = Logger ( label: " Subscriptions " )
463
+ logger. logLevel = . trace
464
+ try await withValkeyClient ( . hostname( valkeyHostname, port: 6379 ) , logger: logger) { client in
465
+ await withThrowingTaskGroup ( of: Void . self) { group in
466
+ group. addTask {
467
+ try await client. withConnection { connection in
468
+ try await connection. subscribe ( to: " testCancelSubscriptions " ) { subscription in
469
+ cont. finish ( )
470
+ for try await _ in subscription {
471
+ }
472
+ }
473
+ #expect( await connection. isSubscriptionsEmpty ( ) )
474
+ }
475
+ }
476
+ await stream. first { _ in true }
477
+ group. cancelAll ( )
478
+ }
479
+ }
480
+ }
481
+
458
482
@Test
459
483
@available ( valkeySwift 1 . 0 , * )
460
484
func testClientSubscriptions( ) async throws {
@@ -481,6 +505,27 @@ struct GeneratedCommands {
481
505
}
482
506
}
483
507
508
+ @Test
509
+ @available ( valkeySwift 1 . 0 , * )
510
+ func testClientCancelSubscription( ) async throws {
511
+ let ( stream, cont) = AsyncStream . makeStream ( of: Void . self)
512
+ var logger = Logger ( label: " Subscriptions " )
513
+ logger. logLevel = . trace
514
+ try await withValkeyClient ( . hostname( valkeyHostname, port: 6379 ) , logger: logger) { client in
515
+ await withThrowingTaskGroup ( of: Void . self) { group in
516
+ group. addTask {
517
+ try await client. subscribe ( to: " testCancelSubscriptions " ) { subscription in
518
+ cont. finish ( )
519
+ for try await _ in subscription {
520
+ }
521
+ }
522
+ }
523
+ await stream. first { _ in true }
524
+ group. cancelAll ( )
525
+ }
526
+ }
527
+ }
528
+
484
529
/// Test two different subscriptions to the same channel both receive messages and that when one ends the other still
485
530
/// receives messages
486
531
@Test
@@ -824,32 +869,4 @@ struct GeneratedCommands {
824
869
}
825
870
}
826
871
}
827
-
828
- @available ( valkeySwift 1 . 0 , * )
829
- @Test
830
- func testGEOPOS( ) async throws {
831
- var logger = Logger ( label: " Valkey " )
832
- logger. logLevel = . trace
833
- try await withValkeyConnection ( . hostname( valkeyHostname, port: 6379 ) , logger: logger) { connection in
834
- try await withKey ( connection: connection) { key in
835
- let count = try await connection. geoadd (
836
- key,
837
- datas: [ . init( longitude: 1.0 , latitude: 53.0 , member: " Edinburgh " ) , . init( longitude: 1.4 , latitude: 53.5 , member: " Glasgow " ) ]
838
- )
839
- #expect( count == 2 )
840
- let search = try await connection. geosearch (
841
- key,
842
- from: . fromlonlat( . init( longitude: 0.0 , latitude: 53.0 ) ) ,
843
- by: . circle( . init( radius: 10000 , unit: . mi) ) ,
844
- withcoord: true ,
845
- withdist: true ,
846
- withhash: true
847
- )
848
- print ( search. map { $0. member } )
849
- try print ( search. map { try $0. attributes [ 0 ] . decode ( as: Double . self) } )
850
- try print ( search. map { try $0. attributes [ 1 ] . decode ( as: String . self) } )
851
- try print ( search. map { try $0. attributes [ 2 ] . decode ( as: GeoCoordinates . self) } )
852
- }
853
- }
854
- }
855
872
}
0 commit comments