From e99490a0dd9d495f7617b7738527ee5f9f0b93b3 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 4 Nov 2021 16:29:07 +0100 Subject: [PATCH] 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 --- .../protocols/http2_request/example_test.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/protocols/http2_request/example_test.py b/examples/protocols/http2_request/example_test.py index 33c60115b1..7e0389413c 100644 --- a/examples/protocols/http2_request/example_test.py +++ b/examples/protocols/http2_request/example_test.py @@ -16,13 +16,16 @@ TEST_SERVER = 'http2.golang.org' def is_test_server_available(): # type: () -> bool # 443 - default https port - conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10) - conn.request('GET', '/') - resp = conn.getresponse() - conn.close() - if resp.status == HTTP_OK: - return True - return False + try: + conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10) + conn.request('GET', '/') + resp = conn.getresponse() + return True if resp.status == HTTP_OK else False + except Exception as msg: + 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')