Skip to content

Commit 8776449

Browse files
authored
Merge pull request #65 from DataDog/matt/tox
Matt/tox
2 parents 9def4d5 + 81484f7 commit 8776449

File tree

2 files changed

+91
-54
lines changed

2 files changed

+91
-54
lines changed

tests/wait-for-services.py

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,70 @@
11
import sys
22
import time
3-
4-
from psycopg2 import connect, OperationalError
5-
from cassandra.cluster import Cluster, NoHostAvailable
3+
import traceback
64

75
from contrib.config import POSTGRES_CONFIG, CASSANDRA_CONFIG
86

9-
107
def try_until_timeout(exception):
118
"""
129
Utility decorator that tries to call a check until there is a timeout.
1310
The default timeout is about 20 seconds.
1411
"""
1512
def wrap(fn):
1613
def wrapper(*args, **kwargs):
17-
for attempt in range(100):
14+
for i in range(100):
1815
try:
1916
fn()
2017
except exception:
21-
time.sleep(0.2)
18+
if i % 20 == 0:
19+
print(traceback.format_exc())
20+
time.sleep(0.25)
2221
else:
2322
break;
2423
else:
2524
sys.exit(1)
2625
return wrapper
2726
return wrap
2827

28+
def check_postgres():
29+
try:
30+
from psycopg2 import connect, OperationalError
31+
except ImportError:
32+
return False
33+
34+
@try_until_timeout(OperationalError)
35+
def _ping():
36+
conn = connect(**POSTGRES_CONFIG)
37+
try:
38+
conn.cursor().execute("SELECT 1;")
39+
finally:
40+
conn.close()
41+
42+
_ping()
43+
44+
45+
def check_cassandra():
46+
try:
47+
from cassandra.cluster import Cluster, NoHostAvailable
48+
except ImportError:
49+
return False
50+
51+
print('checking cass')
52+
53+
# wait for cassandra connection
54+
@try_until_timeout(NoHostAvailable)
55+
def _ping():
56+
with Cluster(**CASSANDRA_CONFIG).connect() as conn:
57+
conn.execute("SELECT now() FROM system.local")
2958

30-
# wait for a psycopg2 connection
31-
@try_until_timeout(OperationalError)
32-
def postgresql_check():
33-
with connect(**POSTGRES_CONFIG) as conn:
34-
conn.cursor().execute("SELECT 1;")
59+
_ping()
3560

3661

37-
# wait for cassandra connection
38-
@try_until_timeout(NoHostAvailable)
39-
def cassandra_check():
40-
with Cluster(**CASSANDRA_CONFIG).connect() as conn:
41-
conn.execute("SELECT now() FROM system.local")
62+
def check():
63+
print("checking services")
64+
check_postgres()
65+
check_cassandra()
66+
print("services checked")
4267

68+
if __name__ == '__main__':
69+
check()
4370

44-
# checks list
45-
print("Waiting for backing services...")
46-
postgresql_check()
47-
cassandra_check()
48-
print("All backing services are up and running!")

tox.ini

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,66 @@
33
# versions.
44

55
[tox]
6-
# Our various test environments. The py*-all tasks will run
7-
# common tests and all contrib tests with the latest library versions.
6+
# Our various test environments. The py*-all tasks will run the core
7+
# library tests and all contrib tests with the latest library versions.
88
# The others will test specific versions of libraries.
99
envlist =
10-
{py34}-wait-for-services
11-
{py27,py34}-all
10+
wait
11+
flake8
1212
{py27,py34}-elasticsearch{23}
1313
{py27,py34}-falcon{10}
14-
{py27,py34}-flask{010,011}
15-
{py27,py34}-flask{010,011}-flaskcache{013}
16-
{py27}-flask{010,011}-flaskcache{012}
17-
{py27,py34}-mysql-connector{21}
14+
{py27,py34}-flask{010,011}-blinker
15+
{py27,py34}-flask{010,011}-flaskcache{013}-memcached-redis-blinker
16+
{py27}-flask{010,011}-flaskcache{012}-memcached-redis-blinker
17+
{py27,py34}-mysqlconnector{21}
1818
{py27,py34}-pylibmc{140,150}
19-
{py27,py34}-pymongo{30,31,32,33}
20-
{py27,py34}-sqlalchemy{10,11}
21-
flake8
19+
{py27,py34}-pymongo{30,31,32,33}-mongoengine
20+
{py27,py34}-sqlalchemy{10,11}-psycopg2
21+
{py27,py34}-all
2222

2323
[testenv]
2424
basepython =
2525
py27: python2.7
2626
py34: python3.4
2727

2828
deps =
29-
# test dependencies
29+
# test dependencies installed in all envs
3030
mock
3131
nose
3232
# integrations
33-
blinker
34-
cassandra-driver
35-
django
33+
all: blinker
34+
all: cassandra-driver
35+
all: django
3636
all: elasticsearch
37-
elasticsearch23: elasticsearch>=2.3,<2.4
3837
all: falcon
39-
falcon10: falcon>=1.0,<1.1
4038
all: flask
39+
all: flask_cache
40+
all: mongoengine
41+
all: mysql-connector
42+
all: psycopg2
43+
all: pylibmc
44+
all: pymongo
45+
all: python-memcached
46+
all: redis
47+
all: sqlalchemy
48+
blinker: blinker
49+
elasticsearch23: elasticsearch>=2.3,<2.4
50+
falcon10: falcon>=1.0,<1.1
4151
flask010: flask>=0.10,<0.11
4252
flask011: flask>=0.11
43-
all: flask_cache
4453
flaskcache012: flask_cache>=0.12,<0.13
4554
flaskcache013: flask_cache>=0.13,<0.14
46-
mongoengine
47-
psycopg2
48-
all: mysql-connector
49-
mysql-connector21: mysql-connector>=2.1,<2.2
50-
all: pylibmc
55+
memcached: python-memcached
56+
mongoengine: mongoengine
57+
mysqlconnector21: mysql-connector>=2.1,<2.2
5158
pylibmc140: pylibmc>=1.4.0,<1.5.0
5259
pylibmc150: pylibmc>=1.5.0
53-
all: pymongo
5460
pymongo30: pymongo>=3.0,<3.1
5561
pymongo31: pymongo>=3.1,<3.2
5662
pymongo32: pymongo>=3.2,<3.3
5763
pymongo33: pymongo>=3.3
58-
redis
59-
python-memcached
60-
all: sqlalchemy
64+
psycopg2: psycopg2
65+
redis: redis
6166
sqlalchemy10: sqlalchemy>=1.0,<1.1
6267
sqlalchemy11: sqlalchemy==1.1.0b3
6368

@@ -66,21 +71,31 @@ passenv=TEST_*
6671

6772
commands =
6873
# wait for services script
69-
{py34}-wait-services: python tests/wait-for-services.py
74+
{py34}-wait: python tests/wait-for-services.py
7075
# run all tests for the release jobs
7176
{py27,py34}-all: nosetests {posargs}
7277
# run subsets of the tests for particular library versions
7378
{py27,py34}-elasticsearch{23}: nosetests {posargs} tests/contrib/elasticsearch
79+
{py27,py34}-flaskcache{013}: nosetests {posargs} tests/contrib/flask_cache
7480
# flask_cache 0.12 is not python 3 compatible
75-
{py27,py34}-flask{010,011}-flaskcache{013}: nosetests {posargs} tests/contrib/flask_cache
76-
{py27}-flask{010,011}-flaskcache{012}: nosetests {posargs} tests/contrib/flask_cache
81+
{py27}-flaskcache{012}: nosetests {posargs} tests/contrib/flask_cache
7782
{py27,py34}-flask{010,011}: nosetests {posargs} tests/contrib/flask
7883
{py27,py34}-falcon{10}: nosetests {posargs} tests/contrib/falcon
79-
{py27,py34}-mysql-connector21}: nosetests {posargs} tests/contrib/mysql
84+
{py27,py34}-mysqlconnector21: nosetests {posargs} tests/contrib/mysql
8085
{py27,py34}-pylibmc{140,150}: nosetests {posargs} tests/contrib/pylibmc
81-
{py27,py34}-pymongo{30,31,32,33}: nosetests {posargs} tests/contrib/pymongo/ tests/contrib/mongoengine
82-
{py27,py34}-sqlalchemy{10,11}: nosetests {posargs} tests/contrib/sqlalchemy tests/contrib/psycopg tests/contrib/sqlite3
86+
{py27,py34}-pymongo{30,31,32,33}: nosetests {posargs} tests/contrib/pymongo/
87+
{py27,py34}-mongoengine: nosetests {posargs} tests/contrib/mongoengine
88+
{py27,py34}-psycopg2: nosetests {posargs} tests/contrib/psycopg
89+
{py27,py34}-sqlalchemy{10,11}: nosetests {posargs} tests/contrib/sqlalchemy
8390

91+
[testenv:wait]
92+
commands=python tests/wait-for-services.py
93+
basepython=python
94+
deps=
95+
cassandra-driver
96+
psycopg2
97+
# this is somewhat flaky (can fail and still be up) so try the tests anyway
98+
ignore_outcome=true
8499

85100
[testenv:flake8]
86101
deps=flake8

0 commit comments

Comments
 (0)