From 4f8e44c8fbd7e7a903580cbe62207b2938d23383 Mon Sep 17 00:00:00 2001 From: manhinhang Date: Thu, 25 Apr 2024 00:24:11 +0800 Subject: [PATCH] test: update tests --- test/test_ib_gateway.py | 24 +++++++++++++++++++++++- test/test_ib_gateway_fail.py | 7 +++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/test/test_ib_gateway.py b/test/test_ib_gateway.py index a28d0da..cec5d86 100644 --- a/test/test_ib_gateway.py +++ b/test/test_ib_gateway.py @@ -23,7 +23,7 @@ def test_healthcheck(): assert subprocess.check_call(['docker', 'exec', docker_id, 'healthcheck']) == 0 subprocess.check_call(['docker', 'rm', '-f', docker_id]) -def test_healthcheck_rest(): +def test_healthcheck_api(): account = os.environ['IB_ACCOUNT'] password = os.environ['IB_PASSWORD'] trading_mode = os.environ['TRADING_MODE'] @@ -41,3 +41,25 @@ def test_healthcheck_rest(): response = requests.get("http://127.0.0.1:8080/healthcheck") assert response.ok subprocess.check_call(['docker', 'rm', '-f', docker_id]) + +def test_healthcheck_api_fail(): + account = 'test' + password = 'test' + trading_mode = os.environ['TRADING_MODE'] + + # run a container + docker_id = subprocess.check_output( + ['docker', 'run', + '--env', 'IB_ACCOUNT={}'.format(account), + '--env', 'IB_PASSWORD={}'.format(password), + '--env', 'TRADING_MODE={}'.format(trading_mode), + '--env', 'HEALTHCHECK_API_ENABLE=true', + '-p', '8080:8080', + '-d', IMAGE_NAME]).decode().strip() + time.sleep(30) + try: + response = requests.get("http://127.0.0.1:8080/healthcheck") + assert not response.ok + except ConnectionResetError: + pass + subprocess.check_call(['docker', 'rm', '-f', docker_id]) diff --git a/test/test_ib_gateway_fail.py b/test/test_ib_gateway_fail.py index 61b622e..3d513c9 100644 --- a/test/test_ib_gateway_fail.py +++ b/test/test_ib_gateway_fail.py @@ -63,5 +63,8 @@ def test_healthcheck_fail(host): def test_healthcheck_rest_fail(host): time.sleep(30) - response = requests.get("http://127.0.0.1:8080/healthcheck") - assert not response.ok \ No newline at end of file + try: + response = requests.get("http://127.0.0.1:8080/healthcheck") + assert False + except ConnectionResetError: + pass