CI: Fix example test for http_request

Test is based on a public http server which might not be always
available, so the example test checks if it's available
so the test could be (by)passed if the public server not available.

But we didn't correctly check if a socket/timeout exception occurs
when trying to connect
This commit is contained in:
David Cermak
2021-11-04 16:29:07 +01:00
parent 465d6a37cc
commit e99490a0dd

View File

@@ -16,13 +16,16 @@ TEST_SERVER = 'http2.golang.org'
def is_test_server_available(): # type: () -> bool def is_test_server_available(): # type: () -> bool
# 443 - default https port # 443 - default https port
conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10) try:
conn.request('GET', '/') conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10)
resp = conn.getresponse() conn.request('GET', '/')
conn.close() resp = conn.getresponse()
if resp.status == HTTP_OK: return True if resp.status == HTTP_OK else False
return True except Exception as msg:
return False Utility.console_log('Exception occurred when connecting to {}: {}'.format(TEST_SERVER, msg))
return False
finally:
conn.close()
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1') @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')