def test_vcr_with_tracing( tmpdir, mock_server, tracer, tracing_before, tracing_after ): from tchannel import TChannel mock_server.expect_call('hello', 'json').and_write('world').once() path = tmpdir.join('data.yaml') if tracing_before: ch = TChannel('client', trace=True, tracer=tracer) else: ch = TChannel('client') with vcr.use_cassette(str(path)) as cass: response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body assert cass.play_count == 0 assert path.check(file=True) if tracing_after: ch = TChannel('client', trace=True, tracer=tracer) else: ch = TChannel('client') with vcr.use_cassette(str(path), record_mode=vcr.RecordMode.NONE) as cass: response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body assert cass.play_count == 1
def test_vcr_with_tracing(tmpdir, mock_server, tracer, tracing_before, tracing_after): from tchannel import TChannel mock_server.expect_call('hello', 'json').and_write('world').once() path = tmpdir.join('data.yaml') if tracing_before: ch = TChannel('client', trace=True, tracer=tracer) else: ch = TChannel('client') with vcr.use_cassette(str(path)) as cass: response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body assert cass.play_count == 0 assert path.check(file=True) if tracing_after: ch = TChannel('client', trace=True, tracer=tracer) else: ch = TChannel('client') with vcr.use_cassette(str(path), record_mode=vcr.RecordMode.NONE) as cass: response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body assert cass.play_count == 1
def test_old_recording_without_tracing(mock_server, tracer): from tchannel import TChannel # an existing recording that does not contain tracing information path = os.path.join(os.path.dirname(__file__), 'data', 'old_without_tracing.yaml') ch = TChannel('client', trace=True, tracer=tracer) mock_server.expect_call('hello', 'json').and_write('world').once() with vcr.use_cassette(path, record_mode=vcr.RecordMode.NONE): response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body
def test_old_recording_without_tracing(mock_server, tracer): from tchannel import TChannel # an existing recording that does not contain tracing information path = os.path.join( os.path.dirname(__file__), 'data', 'old_without_tracing.yaml' ) ch = TChannel('client', trace=True, tracer=tracer) mock_server.expect_call('hello', 'json').and_write('world').once() with vcr.use_cassette(path, record_mode=vcr.RecordMode.NONE): response = yield ch.json( hostport=mock_server.hostport, service='hello_service', endpoint='hello', body='world', ) assert 'world' == response.body