Skip to content

Commit a4d278c

Browse files
authored
Migrate from Travis to CircleCI for tests. (#153)
* Migrate from Travis to CircleCI for tests. * Also install test reqs * Tabs to whitespaces in 2019 * Unify bkgrnd server ports; > 10k * Assure pip is latest * Update egg info prior to test run * Bind to ipv4 address only for docker based tests * Break out port for individual tests * Fix wrong keyname * WSGI: test against configured port * Update default db creds for CircleCI * Update postgres image * Alt db name * Add Rabbitmq to test image
1 parent 2be4705 commit a4d278c

14 files changed

+190
-118
lines changed

.circleci/config.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
11+
- image: circleci/python:3.6.1
12+
13+
# Specify service dependencies here if necessary
14+
# CircleCI maintains a library of pre-built images
15+
# documented at https://circleci.com/docs/2.0/circleci-images/
16+
- image: circleci/postgres:9.6.5-alpine-ram
17+
- image: circleci/mysql:8.0.16
18+
- image: circleci/redis:5.0.4
19+
- image: rabbitmq:3.5.4
20+
21+
working_directory: ~/repo
22+
23+
steps:
24+
- checkout
25+
26+
# Download and cache dependencies
27+
- restore_cache:
28+
keys:
29+
- v1-dependencies-{{ checksum "requirements.txt" }}
30+
# fallback to using the latest cache if no exact match is found
31+
- v1-dependencies-
32+
33+
- run:
34+
name: install dependencies
35+
command: |
36+
python3 -m venv venv
37+
. venv/bin/activate
38+
pip install -U pip
39+
python setup.py install_egg_info
40+
pip install -r requirements.txt
41+
pip install -r requirements-test.txt
42+
43+
- save_cache:
44+
paths:
45+
- ./venv
46+
key: v1-dependencies-{{ checksum "requirements.txt" }}
47+
48+
- run:
49+
name: run tests
50+
command: |
51+
. venv/bin/activate
52+
python runtests.py
53+
54+
- store_artifacts:
55+
path: test-reports
56+
destination: test-reports
File renamed without changes.

tests/apps/app_aiohttp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
13
import asyncio
24
from aiohttp import web
35

46
from ..helpers import testenv
57

6-
testenv["aiohttp_server"] = "http://127.0.0.1:5002"
8+
9+
testenv["aiohttp_port"] = 10810
10+
testenv["aiohttp_server"] = ("http://127.0.0.1:" + str(testenv["aiohttp_port"]))
711

812

913
def say_hello(request):
@@ -29,7 +33,7 @@ def run_server():
2933

3034
runner = web.AppRunner(app)
3135
loop.run_until_complete(runner.setup())
32-
site = web.TCPSite(runner, 'localhost', 5002)
36+
site = web.TCPSite(runner, '127.0.0.1', testenv["aiohttp_port"])
3337

3438
loop.run_until_complete(site.start())
3539
loop.run_forever()

tests/apps/app_django.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
13
import os
24
import sys
35
import time

tests/apps/flaskalino.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
from flask import Flask, redirect
55
from instana.wsgi import iWSGIMiddleware
66
from wsgiref.simple_server import make_server
7-
from instana.singletons import tracer
87

8+
from instana.singletons import tracer
99
from ..helpers import testenv
1010

11-
testenv["wsgi_server"] = "http://127.0.0.1:5000"
11+
12+
testenv["wsgi_port"] = 10811
13+
testenv["wsgi_server"] = ("http://127.0.0.1:" + str(testenv["wsgi_port"]))
1214

1315
app = Flask(__name__)
1416
app.debug = False
1517
app.use_reloader = False
1618

1719
wsgi_app = iWSGIMiddleware(app.wsgi_app)
18-
flask_server = make_server('127.0.0.1', 5000, wsgi_app)
20+
flask_server = make_server('127.0.0.1', testenv["wsgi_port"], wsgi_app)
1921

2022

2123
@app.route("/")

tests/apps/soapserver4132.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
# vim: set fileencoding=UTF-8 :
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
23
import logging
34
from wsgiref.simple_server import make_server
45

5-
from spyne import (Application, Fault, Integer, Iterable, ServiceBase, Unicode,
6-
rpc)
6+
from spyne import (Application, Fault, Integer, Iterable, ServiceBase, Unicode, rpc)
77
from spyne.protocol.soap import Soap11
88
from spyne.server.wsgi import WsgiApplication
99

1010
from instana.wsgi import iWSGIMiddleware
11-
1211
from ..helpers import testenv
1312

14-
testenv["soap_server"] = "http://127.0.0.1:4132"
13+
14+
testenv["soap_port"] = 10812
15+
testenv["soap_server"] = ("http://127.0.0.1:" + str(testenv["soap_port"]))
1516

1617

1718
# Simple in test suite SOAP server to test suds client instrumentation against.
1819
# Configured to listen on localhost port 4132
1920
# WSDL: http://localhost:4232/?wsdl
20-
21-
2221
class StanSoapService(ServiceBase):
2322
@rpc(Unicode, Integer, _returns=Iterable(Unicode))
2423
def ask_question(ctx, question, answer):
@@ -59,7 +58,7 @@ def client_fault(ctx):
5958

6059
# Use Instana middleware so we can test context passing and Soap server traces.
6160
wsgi_app = iWSGIMiddleware(WsgiApplication(app))
62-
soapserver = make_server('127.0.0.1', 4132, wsgi_app)
61+
soapserver = make_server('127.0.0.1', testenv["soap_port"], wsgi_app)
6362

6463
if __name__ == '__main__':
6564
soapserver.serve_forever()

tests/apps/tornado.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
13
import os.path
24
import tornado.auth
35
import tornado.escape
@@ -10,7 +12,9 @@
1012

1113
from ..helpers import testenv
1214

13-
testenv["tornado_server"] = "http://127.0.0.1:4133"
15+
16+
testenv["tornado_port"] = 10813
17+
testenv["tornado_server"] = ("http://127.0.0.1:" + str(testenv["tornado_port"]))
1418

1519

1620
class Application(tornado.web.Application):
@@ -68,5 +72,5 @@ def run_server():
6872
asyncio.set_event_loop(loop)
6973

7074
http_server = tornado.httpserver.HTTPServer(Application())
71-
http_server.listen(4133)
75+
http_server.listen(testenv["tornado_port"])
7276
tornado.ioloop.IOLoop.current().start()

tests/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
testenv['mysql_host'] = '127.0.0.1'
1414

1515
testenv['mysql_port'] = int(os.environ.get('MYSQL_PORT', '3306'))
16-
testenv['mysql_db'] = os.environ.get('MYSQL_DB', 'travis_ci_test')
16+
testenv['mysql_db'] = os.environ.get('MYSQL_DB', 'circle_test')
1717
testenv['mysql_user'] = os.environ.get('MYSQL_USER', 'root')
1818

1919
if 'MYSQL_PW' in os.environ:
@@ -34,8 +34,8 @@
3434
testenv['postgresql_host'] = '127.0.0.1'
3535

3636
testenv['postgresql_port'] = int(os.environ.get('POSTGRESQL_PORT', '3306'))
37-
testenv['postgresql_db'] = os.environ.get('POSTGRESQL_DB', 'travis_ci_test')
38-
testenv['postgresql_user'] = os.environ.get('POSTGRESQL_USER', 'postgres')
37+
testenv['postgresql_db'] = os.environ.get('POSTGRESQL_DB', 'circle_test')
38+
testenv['postgresql_user'] = os.environ.get('POSTGRESQL_USER', 'root')
3939

4040
if 'POSTGRESQL_PW' in os.environ:
4141
testenv['postgresql_pw'] = os.environ['POSTGRESQL_PW']

tests/test_aiohttp.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
class TestAiohttp(unittest.TestCase):
13+
1314
async def fetch(self, session, url, headers=None):
1415
try:
1516
async with session.get(url, headers=headers) as response:
@@ -65,7 +66,7 @@ async def test():
6566

6667
self.assertEqual("aiohttp-client", aiohttp_span.n)
6768
self.assertEqual(200, aiohttp_span.data.http.status)
68-
self.assertEqual("http://127.0.0.1:5000/", aiohttp_span.data.http.url)
69+
self.assertEqual(testenv["wsgi_server"] + "/", aiohttp_span.data.http.url)
6970
self.assertEqual("GET", aiohttp_span.data.http.method)
7071
self.assertIsNotNone(aiohttp_span.stack)
7172
self.assertTrue(type(aiohttp_span.stack) is list)
@@ -121,7 +122,7 @@ async def test():
121122

122123
self.assertEqual("aiohttp-client", aiohttp_span.n)
123124
self.assertEqual(200, aiohttp_span.data.http.status)
124-
self.assertEqual("http://127.0.0.1:5000/301", aiohttp_span.data.http.url)
125+
self.assertEqual(testenv["wsgi_server"] + "/301", aiohttp_span.data.http.url)
125126
self.assertEqual("GET", aiohttp_span.data.http.method)
126127
self.assertIsNotNone(aiohttp_span.stack)
127128
self.assertTrue(type(aiohttp_span.stack) is list)
@@ -172,7 +173,7 @@ async def test():
172173

173174
self.assertEqual("aiohttp-client", aiohttp_span.n)
174175
self.assertEqual(405, aiohttp_span.data.http.status)
175-
self.assertEqual("http://127.0.0.1:5000/405", aiohttp_span.data.http.url)
176+
self.assertEqual(testenv["wsgi_server"] + "/405", aiohttp_span.data.http.url)
176177
self.assertEqual("GET", aiohttp_span.data.http.method)
177178
self.assertIsNotNone(aiohttp_span.stack)
178179
self.assertTrue(type(aiohttp_span.stack) is list)
@@ -224,7 +225,7 @@ async def test():
224225

225226
self.assertEqual("aiohttp-client", aiohttp_span.n)
226227
self.assertEqual(500, aiohttp_span.data.http.status)
227-
self.assertEqual("http://127.0.0.1:5000/500", aiohttp_span.data.http.url)
228+
self.assertEqual(testenv["wsgi_server"] + "/500", aiohttp_span.data.http.url)
228229
self.assertEqual("GET", aiohttp_span.data.http.method)
229230
self.assertEqual('INTERNAL SERVER ERROR', aiohttp_span.data.http.error)
230231
self.assertIsNotNone(aiohttp_span.stack)
@@ -276,7 +277,7 @@ async def test():
276277

277278
self.assertEqual("aiohttp-client", aiohttp_span.n)
278279
self.assertEqual(504, aiohttp_span.data.http.status)
279-
self.assertEqual("http://127.0.0.1:5000/504", aiohttp_span.data.http.url)
280+
self.assertEqual(testenv["wsgi_server"] + "/504", aiohttp_span.data.http.url)
280281
self.assertEqual("GET", aiohttp_span.data.http.method)
281282
self.assertEqual('GATEWAY TIMEOUT', aiohttp_span.data.http.error)
282283
self.assertIsNotNone(aiohttp_span.stack)
@@ -328,7 +329,7 @@ async def test():
328329

329330
self.assertEqual("aiohttp-client", aiohttp_span.n)
330331
self.assertEqual(200, aiohttp_span.data.http.status)
331-
self.assertEqual("http://127.0.0.1:5000/", aiohttp_span.data.http.url)
332+
self.assertEqual(testenv["wsgi_server"] + "/", aiohttp_span.data.http.url)
332333
self.assertEqual("GET", aiohttp_span.data.http.method)
333334
self.assertEqual("secret=<redacted>", aiohttp_span.data.http.params)
334335
self.assertIsNotNone(aiohttp_span.stack)
@@ -425,15 +426,15 @@ async def test():
425426

426427
self.assertEqual("aiohttp-server", aioserver_span.n)
427428
self.assertEqual(200, aioserver_span.data.http.status)
428-
self.assertEqual("http://127.0.0.1:5002/", aioserver_span.data.http.url)
429+
self.assertEqual(testenv["aiohttp_server"] + "/", aioserver_span.data.http.url)
429430
self.assertEqual("GET", aioserver_span.data.http.method)
430431
self.assertIsNotNone(aioserver_span.stack)
431432
self.assertTrue(type(aioserver_span.stack) is list)
432433
self.assertTrue(len(aioserver_span.stack) > 1)
433434

434435
self.assertEqual("aiohttp-client", aioclient_span.n)
435436
self.assertEqual(200, aioclient_span.data.http.status)
436-
self.assertEqual("http://127.0.0.1:5002/", aioclient_span.data.http.url)
437+
self.assertEqual(testenv["aiohttp_server"] + "/", aioclient_span.data.http.url)
437438
self.assertEqual("GET", aioclient_span.data.http.method)
438439
self.assertIsNotNone(aioclient_span.stack)
439440
self.assertTrue(type(aioclient_span.stack) is list)
@@ -484,7 +485,7 @@ async def test():
484485

485486
self.assertEqual("aiohttp-server", aioserver_span.n)
486487
self.assertEqual(200, aioserver_span.data.http.status)
487-
self.assertEqual("http://127.0.0.1:5002/", aioserver_span.data.http.url)
488+
self.assertEqual(testenv["aiohttp_server"] + "/", aioserver_span.data.http.url)
488489
self.assertEqual("GET", aioserver_span.data.http.method)
489490
self.assertEqual("secret=<redacted>", aioserver_span.data.http.params)
490491
self.assertIsNotNone(aioserver_span.stack)
@@ -493,7 +494,7 @@ async def test():
493494

494495
self.assertEqual("aiohttp-client", aioclient_span.n)
495496
self.assertEqual(200, aioclient_span.data.http.status)
496-
self.assertEqual("http://127.0.0.1:5002/", aioclient_span.data.http.url)
497+
self.assertEqual(testenv["aiohttp_server"] + "/", aioclient_span.data.http.url)
497498
self.assertEqual("GET", aioclient_span.data.http.method)
498499
self.assertEqual("secret=<redacted>", aioclient_span.data.http.params)
499500
self.assertIsNotNone(aioclient_span.stack)
@@ -553,7 +554,7 @@ async def test():
553554

554555
self.assertEqual("aiohttp-server", aioserver_span.n)
555556
self.assertEqual(200, aioserver_span.data.http.status)
556-
self.assertEqual("http://127.0.0.1:5002/", aioserver_span.data.http.url)
557+
self.assertEqual(testenv["aiohttp_server"] + "/", aioserver_span.data.http.url)
557558
self.assertEqual("GET", aioserver_span.data.http.method)
558559
self.assertEqual("secret=<redacted>", aioserver_span.data.http.params)
559560
self.assertIsNotNone(aioserver_span.stack)
@@ -562,7 +563,7 @@ async def test():
562563

563564
self.assertEqual("aiohttp-client", aioclient_span.n)
564565
self.assertEqual(200, aioclient_span.data.http.status)
565-
self.assertEqual("http://127.0.0.1:5002/", aioclient_span.data.http.url)
566+
self.assertEqual(testenv["aiohttp_server"] + "/", aioclient_span.data.http.url)
566567
self.assertEqual("GET", aioclient_span.data.http.method)
567568
self.assertEqual("secret=<redacted>", aioclient_span.data.http.params)
568569
self.assertIsNotNone(aioclient_span.stack)
@@ -619,15 +620,15 @@ async def test():
619620

620621
self.assertEqual("aiohttp-server", aioserver_span.n)
621622
self.assertEqual(401, aioserver_span.data.http.status)
622-
self.assertEqual("http://127.0.0.1:5002/401", aioserver_span.data.http.url)
623+
self.assertEqual(testenv["aiohttp_server"] + "/401", aioserver_span.data.http.url)
623624
self.assertEqual("GET", aioserver_span.data.http.method)
624625
self.assertIsNotNone(aioserver_span.stack)
625626
self.assertTrue(type(aioserver_span.stack) is list)
626627
self.assertTrue(len(aioserver_span.stack) > 1)
627628

628629
self.assertEqual("aiohttp-client", aioclient_span.n)
629630
self.assertEqual(401, aioclient_span.data.http.status)
630-
self.assertEqual("http://127.0.0.1:5002/401", aioclient_span.data.http.url)
631+
self.assertEqual(testenv["aiohttp_server"] + "/401", aioclient_span.data.http.url)
631632
self.assertEqual("GET", aioclient_span.data.http.method)
632633
self.assertIsNotNone(aioclient_span.stack)
633634
self.assertTrue(type(aioclient_span.stack) is list)
@@ -678,15 +679,15 @@ async def test():
678679

679680
self.assertEqual("aiohttp-server", aioserver_span.n)
680681
self.assertEqual(500, aioserver_span.data.http.status)
681-
self.assertEqual("http://127.0.0.1:5002/500", aioserver_span.data.http.url)
682+
self.assertEqual(testenv["aiohttp_server"] + "/500", aioserver_span.data.http.url)
682683
self.assertEqual("GET", aioserver_span.data.http.method)
683684
self.assertIsNotNone(aioserver_span.stack)
684685
self.assertTrue(type(aioserver_span.stack) is list)
685686
self.assertTrue(len(aioserver_span.stack) > 1)
686687

687688
self.assertEqual("aiohttp-client", aioclient_span.n)
688689
self.assertEqual(500, aioclient_span.data.http.status)
689-
self.assertEqual("http://127.0.0.1:5002/500", aioclient_span.data.http.url)
690+
self.assertEqual(testenv["aiohttp_server"] + "/500", aioclient_span.data.http.url)
690691
self.assertEqual("GET", aioclient_span.data.http.method)
691692
self.assertEqual('I must simulate errors.', aioclient_span.data.http.error)
692693
self.assertIsNotNone(aioclient_span.stack)

tests/test_sudsjurko.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
from instana.singletons import tracer
77

8+
from .helpers import testenv
9+
810

911
class TestSudsJurko:
1012
def setUp(self):
1113
""" Clear all spans before a test run """
12-
self.client = Client('http://localhost:4132/?wsdl', cache=None)
14+
self.client = Client(testenv["soap_server"] + '/?wsdl', cache=None)
1315
self.recorder = tracer.recorder
1416
self.recorder.clear_spans()
1517
tracer.cur_ctx = None
@@ -53,7 +55,7 @@ def test_basic_request(self):
5355
assert_equals(None, soap_span.ec)
5456

5557
assert_equals('ask_question', soap_span.data.soap.action)
56-
assert_equals('http://localhost:4132/', soap_span.data.http.url)
58+
assert_equals(testenv["soap_server"] + '/', soap_span.data.http.url)
5759

5860
def test_server_exception(self):
5961
response = None
@@ -90,7 +92,7 @@ def test_server_exception(self):
9092
soap_span.data.custom.logs[tskey]['message'])
9193

9294
assert_equals('server_exception', soap_span.data.soap.action)
93-
assert_equals('http://localhost:4132/', soap_span.data.http.url)
95+
assert_equals(testenv["soap_server"] + '/', soap_span.data.http.url)
9496

9597
def test_server_fault(self):
9698
response = None
@@ -126,7 +128,7 @@ def test_server_fault(self):
126128
soap_span.data.custom.logs[tskey]['message'])
127129

128130
assert_equals('server_fault', soap_span.data.soap.action)
129-
assert_equals('http://localhost:4132/', soap_span.data.http.url)
131+
assert_equals(testenv["soap_server"] + '/', soap_span.data.http.url)
130132

131133
def test_client_fault(self):
132134
response = None
@@ -163,4 +165,4 @@ def test_client_fault(self):
163165
soap_span.data.custom.logs[tskey]['message'])
164166

165167
assert_equals('client_fault', soap_span.data.soap.action)
166-
assert_equals('http://localhost:4132/', soap_span.data.http.url)
168+
assert_equals(testenv["soap_server"] + '/', soap_span.data.http.url)

0 commit comments

Comments
 (0)