11# 3p
22import mysql
3- from nose .tools import eq_
3+ from nose .tools import eq_ , ok_
44
55# project
66from ddtrace import Pin
1111
1212
1313class MySQLCore (object ):
14-
15- # Reuse the connection across tests
14+ """Base test case for MySQL drivers"""
1615 conn = None
1716 TEST_SERVICE = 'test-mysql'
1817
1918 def tearDown (self ):
20- if self .conn and self .conn .is_connected ():
21- self .conn .close ()
19+ # Reuse the connection across tests
20+ if self .conn :
21+ try :
22+ self .conn .ping ()
23+ except MySQLdb .InterfaceError :
24+ pass
25+ else :
26+ self .conn .close ()
2227 unpatch ()
2328
2429 def _get_conn_tracer (self ):
@@ -45,9 +50,7 @@ def test_simple_query(self):
4550 'out.port' : u'3306' ,
4651 'db.name' : u'test' ,
4752 'db.user' : u'test' ,
48- 'sql.query' : u'SELECT 1' ,
4953 })
50- # eq_(span.get_metric('sql.rows'), -1)
5154
5255 def test_query_with_several_rows (self ):
5356 conn , tracer = self ._get_conn_tracer ()
@@ -60,8 +63,7 @@ def test_query_with_several_rows(self):
6063 spans = writer .pop ()
6164 eq_ (len (spans ), 1 )
6265 span = spans [0 ]
63- eq_ (span .get_tag ('sql.query' ), query )
64- # eq_(span.get_tag('sql.rows'), 3)
66+ ok_ (span .get_tag ('sql.query' ) is None )
6567
6668 def test_query_many (self ):
6769 # tests that the executemany method is correctly wrapped.
@@ -92,7 +94,7 @@ def test_query_many(self):
9294 spans = writer .pop ()
9395 eq_ (len (spans ), 2 )
9496 span = spans [- 1 ]
95- eq_ (span .get_tag ('sql.query' ), query )
97+ ok_ (span .get_tag ('sql.query' ) is None )
9698 cursor .execute ("drop table if exists dummy" )
9799
98100 def test_query_proc (self ):
@@ -132,9 +134,8 @@ def test_query_proc(self):
132134 'out.port' : u'3306' ,
133135 'db.name' : u'test' ,
134136 'db.user' : u'test' ,
135- 'sql.query' : u'sp_sum' ,
136137 })
137- # eq_ (span.get_metric ('sql.rows'), 1 )
138+ ok_ (span .get_tag ('sql.query' ) is None )
138139
139140
140141class TestMysqlPatch (MySQLCore ):
@@ -197,8 +198,8 @@ def test_patch_unpatch(self):
197198 'out.port' : u'3306' ,
198199 'db.name' : u'test' ,
199200 'db.user' : u'test' ,
200- 'sql.query' : u'SELECT 1' ,
201201 })
202+ ok_ (span .get_tag ('sql.query' ) is None )
202203
203204 finally :
204205 unpatch ()
0 commit comments