@@ -11,7 +11,7 @@ use anyhow::Context;
1111
1212use super :: client_role:: ClientRole ;
1313use super :: qbittorrent:: QbittorrentClient ;
14- use super :: tracker:: TrackerConfig ;
14+ use super :: tracker:: { TrackerApiClient , TrackerConfig } ;
1515use super :: types:: { ComposeProjectName , QbittorrentImage , TrackerImage } ;
1616use super :: workspace:: WorkspaceResources ;
1717use crate :: console:: ci:: compose:: { DockerCompose , RunningCompose } ;
@@ -33,7 +33,7 @@ pub(crate) async fn start(
3333 qbittorrent_image : & QbittorrentImage ,
3434 resources : & WorkspaceResources ,
3535 tracker_config : & TrackerConfig ,
36- ) -> anyhow:: Result < ( RunningCompose , QbittorrentClient , QbittorrentClient ) > {
36+ ) -> anyhow:: Result < ( RunningCompose , QbittorrentClient , QbittorrentClient , TrackerApiClient ) > {
3737 let compose = configure_compose (
3838 compose_file,
3939 project_name,
@@ -44,8 +44,10 @@ pub(crate) async fn start(
4444 ) ?;
4545 compose. build ( ) . context ( "failed to build local tracker image" ) ?;
4646 let running_compose = compose. up ( ) . context ( "failed to start qBittorrent compose stack" ) ?;
47- let ( seeder, leecher) = build_clients ( & compose, resources. timing . polling_deadline . as_duration ( ) ) . await ?;
48- Ok ( ( running_compose, seeder, leecher) )
47+ let timeout = resources. timing . polling_deadline . as_duration ( ) ;
48+ let ( seeder, leecher) = build_clients ( & compose, timeout) . await ?;
49+ let tracker = build_tracker_api_client ( & compose, tracker_config, timeout) . await ?;
50+ Ok ( ( running_compose, seeder, leecher, tracker) )
4951}
5052
5153async fn build_clients ( compose : & DockerCompose , timeout : Duration ) -> anyhow:: Result < ( QbittorrentClient , QbittorrentClient ) > {
@@ -54,6 +56,22 @@ async fn build_clients(compose: &DockerCompose, timeout: Duration) -> anyhow::Re
5456 Ok ( ( seeder, leecher) )
5557}
5658
59+ async fn build_tracker_api_client (
60+ compose : & DockerCompose ,
61+ tracker_config : & TrackerConfig ,
62+ timeout : Duration ,
63+ ) -> anyhow:: Result < TrackerApiClient > {
64+ let container_port = tracker_config. http_api_bind_address ( ) . port ( ) ;
65+ let host_port = compose
66+ . wait_for_port_mapping ( "tracker" , container_port, timeout, COMPOSE_PORT_POLL_INTERVAL , & [ ] )
67+ . await
68+ . context ( "failed to resolve tracker REST API host port" ) ?;
69+
70+ tracing:: info!( "Tracker REST API host port: {host_port}" ) ;
71+
72+ TrackerApiClient :: new ( host_port, tracker_config) . context ( "failed to build tracker REST API client" )
73+ }
74+
5775async fn build_seeder_client ( compose : & DockerCompose , timeout : Duration ) -> anyhow:: Result < QbittorrentClient > {
5876 let port = wait_for_client_port ( compose, ClientRole :: Seeder , timeout) . await ?;
5977 build_client ( ClientRole :: Seeder , port, timeout)
@@ -98,13 +116,15 @@ fn configure_compose(
98116) -> anyhow:: Result < DockerCompose > {
99117 let tracker_http_tracker_port = tracker_config. http_tracker_bind_address ( ) . port ( ) . to_string ( ) ;
100118 let tracker_udp_port = tracker_config. udp_bind_address ( ) . port ( ) . to_string ( ) ;
119+ let tracker_http_api_port = tracker_config. http_api_bind_address ( ) . port ( ) . to_string ( ) ;
101120 let tracker_health_check_api_port = tracker_config. health_check_api_bind_address ( ) . port ( ) . to_string ( ) ;
102121
103122 Ok ( DockerCompose :: new ( compose_file, project_name. as_str ( ) )
104123 . with_env ( "QBT_E2E_TRACKER_IMAGE" , tracker_image. as_str ( ) )
105124 . with_env ( "QBT_E2E_QBITTORRENT_IMAGE" , qbittorrent_image. as_str ( ) )
106125 . with_env ( "QBT_E2E_TRACKER_HTTP_TRACKER_PORT" , tracker_http_tracker_port. as_str ( ) )
107126 . with_env ( "QBT_E2E_TRACKER_UDP_PORT" , tracker_udp_port. as_str ( ) )
127+ . with_env ( "QBT_E2E_TRACKER_HTTP_API_PORT" , tracker_http_api_port. as_str ( ) )
108128 . with_env (
109129 "QBT_E2E_TRACKER_HEALTH_CHECK_API_PORT" ,
110130 tracker_health_check_api_port. as_str ( ) ,
0 commit comments