Skip to content

Commit 5f83695

Browse files
author
Emanuele Palazzetti
committed
[ci] add integration tests for the downgrade behavior
1 parent f0c0168 commit 5f83695

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

ddtrace/encoding.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import json
32
import logging
43

tests/test_integration.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ddtrace.api import API
1111
from ddtrace.span import Span
1212
from ddtrace.tracer import Tracer
13-
from ddtrace.encoding import JSONEncoder, MsgpackEncoder
13+
from ddtrace.encoding import JSONEncoder, MsgpackEncoder, get_encoder
1414
from tests.test_tracer import get_dummy_tracer
1515

1616

@@ -278,3 +278,44 @@ def test_send_service_called_multiple_times(self):
278278
response = self.api_msgpack.send_services(services)
279279
ok_(response)
280280
eq_(response.status, 200)
281+
282+
@skipUnless(
283+
os.environ.get('TEST_DATADOG_INTEGRATION', False),
284+
'You should have a running trace agent and set TEST_DATADOG_INTEGRATION=1 env variable'
285+
)
286+
class TestAPIDowngrade(TestCase):
287+
"""
288+
Ensures that if the tracing client found an earlier trace agent,
289+
it will downgrade the current connection to a stable API version
290+
"""
291+
def test_get_encoder_default(self):
292+
# get_encoder should return MsgpackEncoder instance if
293+
# msgpack and the CPP implementaiton are available
294+
encoder = get_encoder()
295+
ok_(isinstance(encoder, MsgpackEncoder))
296+
297+
@mock.patch('ddtrace.encoding.MSGPACK_ENCODING', False)
298+
def test_get_encoder_fallback(self):
299+
# get_encoder should return JSONEncoder instance if
300+
# msgpack or the CPP implementaiton, are not available
301+
encoder = get_encoder()
302+
ok_(isinstance(encoder, JSONEncoder))
303+
304+
def test_downgrade_api(self):
305+
# make a call to a not existing endpoint, downgrades
306+
# the current API to a stable one
307+
tracer = get_dummy_tracer()
308+
tracer.trace('client.testing').finish()
309+
trace = tracer.writer.pop()
310+
311+
# the encoder is right but we're targeting an API
312+
# endpoint that is not available
313+
api = API('localhost', 7777)
314+
api._traces = '/v0.0/traces'
315+
ok_(isinstance(api._encoder, MsgpackEncoder))
316+
317+
# after the call, we downgrade to a working endpoint
318+
response = api.send_traces([trace])
319+
ok_(response)
320+
eq_(response.status, 200)
321+
ok_(isinstance(api._encoder, JSONEncoder))

tox.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ envlist =
1111
wait
1212

1313
{py27,py34}-tracer
14+
{py27,py34}-integration
1415
{py27,py34}-contrib
1516
{py27,py34}-bottle{12}-webtest
1617
{py27,py34}-cassandra
@@ -38,7 +39,7 @@ deps =
3839
# test dependencies installed in all envs
3940
mock
4041
nose
41-
msgpack-python<0.4.9
42+
msgpack-python
4243
# integrations
4344
contrib: blinker
4445
contrib: bottle
@@ -101,7 +102,9 @@ commands =
101102
# wait for services script
102103
{py34}-wait: python tests/wait-for-services.py
103104
# run only essential tests related to the tracing client
104-
{py27,py34}-tracer: nosetests {posargs} --exclude=".*(contrib).*" tests/
105+
{py27,py34}-tracer: nosetests {posargs} --exclude=".*(contrib|integration).*" tests/
106+
# integration tests
107+
{py27,py34}-integration: nosetests {posargs} tests/test_integration.py
105108
# run all tests for the release jobs except the ones with a different test runner
106109
{py27,py34}-contrib: nosetests {posargs} --exclude=".*(django).*" tests/contrib/
107110
# run subsets of the tests for particular library versions
@@ -141,5 +144,5 @@ basepython=python
141144

142145
[flake8]
143146
ignore=W391,E231,E201,E202,E203,E261,E302,E128,E126,E124
144-
max-line-length=100
147+
max-line-length=120
145148
exclude = tests

0 commit comments

Comments
 (0)