Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manhinhang committed Apr 24, 2024
1 parent d5b8ac3 commit 4f8e44c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 23 additions & 1 deletion test/test_ib_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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])
7 changes: 5 additions & 2 deletions test/test_ib_gateway_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
try:
response = requests.get("http://127.0.0.1:8080/healthcheck")
assert False
except ConnectionResetError:
pass

0 comments on commit 4f8e44c

Please sign in to comment.