Skip to content

Commit

Permalink
Test suite bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Mar 2, 2024
1 parent cccca70 commit 6c17a86
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/test_ib_gateway_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ def host(request):
password = 'test'
trade_mode = 'paper'

# We start a container with invalid credentials and expect a failure

# run a container
docker_id = subprocess.check_output(
['docker', 'run',
'--env', 'IB_ACCOUNT={}'.format(account),
'--env', 'IB_PASSWORD={}'.format(password),
'--env', 'TRADE_MODE={}'.format(trade_mode),
'-p', '4002:4002', \
'-p', '4002:4002',
'-d', IMAGE_NAME,
'--health-cmd=/usr/bin/true', # Disable health check or container won't start
"tail", "-f", "/dev/null"]).decode().strip()
# return a testinfra connection to the container
yield testinfra.get_host("docker://" + docker_id)
# at the end of the test suite, destroy the container
subprocess.check_call(['docker', 'rm', '-f', docker_id])

# We try to connect to port 22 where IBGW is not supposed to listen
# and should get an error. The test is valid when the script stops with an error
def test_ib_connect_fail(host):
script = """
from ib_insync import *
IB.sleep(60)
ib = IB()
ib.connect('localhost', 22, clientId=998)
ib.connect('localhost', 4002, clientId=998)
ib.disconnect()
"""
cmd = host.run("python -c \"{}\"".format(script))
Expand Down

0 comments on commit 6c17a86

Please sign in to comment.