Skip to content

Commit

Permalink
Add timeout to connection timeout test, display more debug info.
Browse files Browse the repository at this point in the history
  • Loading branch information
termim committed Oct 7, 2020
1 parent 76bd664 commit 0bfd9c2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_linux.yml
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Test with pytest
run: |
pytest
pytest -s
wheels:

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -17,4 +17,9 @@ freetds/
.idea/
venv/
*~
*.bak
.eggs
.eric?project
*.e4p
cython_debug/*

2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -20,7 +20,7 @@ RUN pip install ipython
RUN pip install SQLAlchemy
RUN pip install pandas
RUN pip install Alembic
RUN pip install pytest
RUN pip install pytest pytest-timeout
RUN pip install gevent

# Add source directory to Docker image
Expand Down
4 changes: 2 additions & 2 deletions dev/build_manylinux_wheels.sh
Expand Up @@ -83,9 +83,9 @@ mv wheelhouse/* dist/
# Install the wheels that were built. Need to be able to connect to mssql and to run the pytest suite after install
for PYBIN in /opt/python/*/bin/; do
"${PYBIN}/pip" install pymssql --no-index -f dist
"${PYBIN}/pip" install pytest SQLAlchemy
"${PYBIN}/pip" install pytest pytest-timeout SQLAlchemy
"${PYBIN}/python" -c "import pymssql; pymssql.__version__;"
"${PYBIN}/pytest" .
"${PYBIN}/pytest" -s .
done

# Remove wheel and egg directory for next container build (i686 vs x86_x64)
Expand Down
1 change: 1 addition & 0 deletions dev/requirements-dev.txt
@@ -1,6 +1,7 @@
cython
gevent
pytest
pytest-timeout
setuptools
sqlalchemy
wheel
2 changes: 1 addition & 1 deletion dev/test_manylinux_wheels.sh
Expand Up @@ -12,7 +12,7 @@ fi

# Install Python dependencies and compile wheels
for PYBIN in /opt/python/*/bin; do
"${PYBIN}/pip" install pytest SQLAlchemy Sphinx sphinx-rtd-theme Cython wheel
"${PYBIN}/pip" install pytest pytest-timeout SQLAlchemy Sphinx sphinx-rtd-theme Cython wheel
done

# Install the wheels that were built. Need to be able to connect to mssql and to run the pytest suite after install
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -460,7 +460,7 @@ def run_tests(self):
],
zip_safe = False,
setup_requires=['setuptools_git', 'Cython'],
tests_require=['pytest', 'unittest2'],
tests_require=['pytest', 'pytest-timeout', 'unittest2'],
ext_modules = ext_modules(),

)
24 changes: 13 additions & 11 deletions tests/test_connection_timeout.py
Expand Up @@ -5,15 +5,17 @@
import pymssql


def test_connect_timeout():
@pytest.mark.timeout(120)
@pytest.mark.xfail(strict=False)
@pytest.mark.parametrize('to', range(2,20,2))
def test_remote_connect_timeout(to):

for to in range(2,20,2):
t = time.time()
try:
pymssql.connect(server="www.google.com", port=81, user='username', password='password',
login_timeout=to)
except pymssql.OperationalError:
pass
t = time.time() - t
#print(to, t)
assert t == pytest.approx(to, 1)
t = time.time()
try:
pymssql.connect(server="www.google.com", port=81, user='username', password='password',
login_timeout=to)
except pymssql.OperationalError:
pass
t = time.time() - t
print('remote: requested {} -> {} actual timeout'.format(to, t))
assert t == pytest.approx(to, 5), "{} != {}".format(t, to)

0 comments on commit 0bfd9c2

Please sign in to comment.