152152 OAuth2Client ,
153153)
154154from azul .plugins import (
155+ File ,
155156 MetadataPlugin ,
156157 RepositoryPlugin ,
157158)
@@ -464,7 +465,14 @@ class Catalog:
464465 catalogs : list [Catalog ] = []
465466 for catalog in config .integration_test_catalogs .values ():
466467 if index :
467- public_source , _ = self ._select_source (catalog .name , public = True )
468+ public_source , _ = self ._select_source (
469+ catalog .name ,
470+ public = True ,
471+ # If test_mirroring is run for the catalog, ensure that the
472+ # source is not flagged as no_mirror so that we can test
473+ # downloading a mirrored file
474+ mirror = config .enable_mirroring and catalog .mirror_limit >= 0
475+ )
468476 ma_source = self ._select_source (catalog .name , public = False )
469477 if ma_source is not None :
470478 ma_source = ma_source [0 ]
@@ -505,6 +513,9 @@ class Catalog:
505513 public_source = catalog .public_source ,
506514 ma_source = catalog .ma_source )
507515
516+ if config .enable_mirroring :
517+ self ._test_mirroring (delete = delete )
518+
508519 if index and delete :
509520 # FIXME: Test delete notifications
510521 # https://github.com/DataBiosphere/azul/issues/3548
@@ -517,9 +528,6 @@ class Catalog:
517528
518529 self ._test_other_endpoints ()
519530
520- if config .enable_mirroring :
521- self ._test_mirroring (delete = delete )
522-
523531 def _reset_indexer (self ):
524532 # While it's OK to erase the integration test catalog, the queues are
525533 # shared by all catalogs and we can't afford to trash them in a stable
@@ -750,6 +758,24 @@ def _manifest_urls(self,
750758 urls .append (furl (response .headers ['Location' ]))
751759 return urls
752760
761+ def _get_one_mirrorable_file (self ,
762+ catalog : CatalogName
763+ ) -> tuple [File , SourceRef , JSON ]:
764+ plugin = self .repository_plugin (catalog )
765+ with self ._public_service_account_credentials :
766+ # This depends on the indexing test choosing a public source that
767+ # is not flagged as no_mirror
768+ outer_file , inner_file = self ._get_one_inner_file (catalog )
769+ file_digest = lookup (inner_file , 'sha256' , 'file_md5sum' )
770+ source = one (outer_file ['sources' ])
771+ # In principle, we could use the entire digest here, but Prefix only
772+ # allows up to 8 chars because it can be used with UUIDs
773+ prefix = Prefix (common = file_digest [:8 ], partition = 0 )
774+ source = self ._source_from_response (catalog , source )
775+ files = plugin .list_files (source .with_prefix (prefix ), prefix = prefix .common )
776+ file = one (file for file in files if file .digest .value == file_digest )
777+ return file , source , inner_file
778+
753779 def _get_one_inner_file (self , catalog : CatalogName ) -> tuple [JSON , JSON ]:
754780 outer_file = self ._get_one_outer_file (catalog )
755781 inner_files : JSONs = outer_file ['files' ]
@@ -1748,11 +1774,23 @@ def _delete():
17481774 self ._assert_queues_empty ([config .mirror_queue .name ,
17491775 config .mirror_queue .to_fail .name ])
17501776 _delete ()
1751- for _ in range (2 ):
1752- for catalog , sources in sources_by_catalog .items ():
1753- self .azul_client .remote_mirror (catalog , sources )
1754- self .azul_client .wait_for_mirroring ()
1755- self ._assert_queues_empty ([config .mirror_queue .to_fail .name ])
1777+ indexed_files_by_source : dict [SourceRef , JSON ] = {}
1778+ with self .subTest ('remote_mirror' ):
1779+ for _ in range (2 ):
1780+ for catalog , sources in sources_by_catalog .items ():
1781+ self .azul_client .remote_mirror (catalog , sources )
1782+ repository_file , source , file_response = self ._get_one_mirrorable_file (catalog )
1783+ indexed_files_by_source [source ] = file_response
1784+ file_message = self .azul_client .mirror_file_message (catalog ,
1785+ source ,
1786+ repository_file )
1787+ self .azul_client .queue_mirror_messages ([file_message ])
1788+ self .azul_client .wait_for_mirroring ()
1789+ self ._assert_queues_empty ([config .mirror_queue .to_fail .name ])
1790+
1791+ with self .subTest ('mirror_repository_files' ):
1792+ for source , file_response in indexed_files_by_source .items ():
1793+ self ._test_file_download (source .spec , file_response )
17561794 _delete ()
17571795
17581796
0 commit comments