1313// limitations under the License.
1414use amqprs:: connection:: { Connection , OpenConnectionArguments } ;
1515use rabbitmq_http_client:: api:: Client ;
16+ use std:: time:: Duration ;
1617
1718mod test_helpers;
1819use crate :: test_helpers:: { PASSWORD , USERNAME , endpoint, hostname} ;
1920
2021#[ tokio:: test]
21- async fn test_list_channels ( ) {
22+ async fn test_async_list_channels ( ) {
2223 let endpoint = endpoint ( ) ;
2324 let rc = Client :: new ( & endpoint, USERNAME , PASSWORD ) ;
2425
@@ -38,7 +39,7 @@ async fn test_list_channels() {
3839}
3940
4041#[ tokio:: test]
41- async fn test_list_virtual_host_channels ( ) {
42+ async fn test_async_list_virtual_host_channels ( ) {
4243 let endpoint = endpoint ( ) ;
4344 let rc = Client :: new ( & endpoint, USERNAME , PASSWORD ) ;
4445
@@ -57,3 +58,31 @@ async fn test_list_virtual_host_channels() {
5758 ch. close ( ) . await . unwrap ( ) ;
5859 conn. clone ( ) . close ( ) . await . unwrap ( ) ;
5960}
61+
62+ #[ tokio:: test]
63+ async fn test_async_list_channels_on_connection ( ) {
64+ let endpoint = endpoint ( ) ;
65+ let rc = Client :: new ( & endpoint, USERNAME , PASSWORD ) ;
66+
67+ let args = OpenConnectionArguments :: new ( & hostname ( ) , 5672 , USERNAME , PASSWORD ) ;
68+ let conn = Connection :: open ( & args) . await . unwrap ( ) ;
69+ assert ! ( conn. is_open( ) ) ;
70+
71+ let ch = conn. open_channel ( None ) . await . unwrap ( ) ;
72+ assert ! ( ch. is_open( ) ) ;
73+
74+ tokio:: time:: sleep ( Duration :: from_millis ( 1000 ) ) . await ;
75+
76+ let connections = rc. list_connections ( ) . await . unwrap ( ) ;
77+ let first = connections. first ( ) . unwrap ( ) ;
78+
79+ let result1 = rc. list_channels_on ( & first. name ) . await ;
80+ assert ! ( result1. is_ok( ) , "list_channels_on returned {result1:?}" ) ;
81+
82+ let channels = result1. unwrap ( ) ;
83+ assert_eq ! ( 1 , channels. len( ) ) ;
84+
85+ // just to be explicit
86+ ch. close ( ) . await . unwrap ( ) ;
87+ conn. clone ( ) . close ( ) . await . unwrap ( ) ;
88+ }
0 commit comments