@@ -67,25 +67,42 @@ class LinkTester(BuildTest):
6767 """Make sure all templated links are alive"""
6868
6969 name = 'Links'
70- def __init__ (self , concurrency = 16 , ignore_internal_links = False ):
70+ def __init__ (self , concurrency = 16 , warn = False ):
7171 """
7272 Semaphore limits number of concurrent requests for performance
7373 Is still nonblocking
7474 """
7575 self .concurrency = concurrency
76- self .ignore_internal_links = ignore_internal_links
76+ self .warn_only = warn
7777
78- @staticmethod
79- async def fetch (session , url , lock ):
78+ async def fetch (self , session , url , lock ):
8079 """Locked async HTTP GET"""
8180 async with lock :
8281 try :
8382 return await session .get (url , allow_redirects = False , timeout = TIMEOUT_SEC )
84- except (aiohttp .ClientConnectorSSLError , aiohttp .ClientConnectorCertificateError ):
85- print (f"SSL error when fetching { url } " )
86- return await session .get (url , allow_redirects = False , timeout = TIMEOUT_SEC , ssl = False )
87- except asyncio .exceptions .TimeoutError :
88- print (f"Took too long trying to fetch { url } " )
83+ except (
84+ aiohttp .ClientConnectorSSLError ,
85+ aiohttp .ClientConnectorCertificateError
86+ ) as err :
87+ if self .warn_only :
88+ print (f"SSL error when fetching { url } " )
89+ return await session .get (
90+ url ,
91+ allow_redirects = False ,
92+ timeout = TIMEOUT_SEC ,
93+ ssl = False
94+ )
95+ raise err
96+ except aiohttp .ClientResponseError as err :
97+ if self .warn_only :
98+ print (f"Error fetching { url } , status code: { err .status } " )
99+ else :
100+ raise err
101+ except asyncio .exceptions .TimeoutError as err :
102+ if self .warn_only :
103+ print (f"Took too long trying to fetch { url } " )
104+ else :
105+ raise err
89106
90107 async def get_failures (self , links ):
91108 """
@@ -106,17 +123,17 @@ def _test(self):
106123 def strip_fragment_identifiers (link ):
107124 return link .split ('#' )[0 ]
108125
126+ # formatting
109127 print ()
110128
111- if self .ignore_internal_links :
112- links = set (
113- strip_fragment_identifiers (link ) for template_var , link in links .items ()
114- if not template_var .startswith ('int' )
115- )
116- else :
117- links = set (strip_fragment_identifiers (link ) for link in links .values ())
129+ links = set (strip_fragment_identifiers (link ) for link in links .values ())
118130
119131 fails = asyncio .run (self .get_failures (links ))
132+ if self .warn_only :
133+ print ('\n Additional Warnings:' )
134+ for fail in fails :
135+ print (f'{ fail .url } : { fail .status } ' )
136+ return BuildTestResult (True )
120137 return BuildTestResult (
121138 not bool (fails ),
122139 [f'{ fail .url } : { fail .status } ' for fail in fails ]
0 commit comments