Ejemplo n.º 1
0
    def test_cozydb_cozycursor_retry_select(self):
        cursor1 = CozyCursor(**self.db_args)
        thread_id1 = cursor1.connection.thread_id()

        # Kill connection of cursor1, test re-connect ability then
        cursor2 = CozyCursor(**self.db_args)
        cursor2.execute('kill %d' % thread_id1)

        # wait MySQL server for disconnecting killed connection
        time.sleep(0.02)

        cursor1.execute('select 1', retry=1)
        eq_(cursor1.fetchone(), (1,))
        err_msg = 'Thread id did not change after re-connect, it should be'
        ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
Ejemplo n.º 2
0
    def test_cozydb_cozycursor_retry_select(self):
        cursor1 = CozyCursor(**self.db_args)
        thread_id1 = cursor1.connection.thread_id()

        # Kill connection of cursor1, test re-connect ability then
        cursor2 = CozyCursor(**self.db_args)
        cursor2.execute('kill %d' % thread_id1)

        # wait MySQL server for disconnecting killed connection
        time.sleep(0.02)

        cursor1.execute('select 1', retry=1)
        eq_(cursor1.fetchone(), (1, ))
        err_msg = 'Thread id did not change after re-connect, it should be'
        ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
Ejemplo n.º 3
0
    def test_cozydb_cozycursor_reconnect(self):
        cursor1 = CozyCursor(**self.db_args)
        thread_id1 = cursor1.connection.thread_id()

        # Kill connection of cursor1, test re-connect ability then
        cursor2 = CozyCursor(**self.db_args)
        cursor2.execute('kill %d' % thread_id1)

        # wait MySQL server for disconnecting killed connection
        time.sleep(0.02)

        try:
            cursor1.execute('select 1')
        except MySQLdb.OperationalError:
            pass
        else:
            ok_(False, '%r connection did not break, it should be' % cursor1)

        cursor1.execute('select 1')
        eq_(cursor1.fetchone(), (1,))
        err_msg = 'Thread id did not change after re-connect, it should be'
        ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
Ejemplo n.º 4
0
    def test_cozydb_cozycursor_reconnect(self):
        cursor1 = CozyCursor(**self.db_args)
        thread_id1 = cursor1.connection.thread_id()

        # Kill connection of cursor1, test re-connect ability then
        cursor2 = CozyCursor(**self.db_args)
        cursor2.execute('kill %d' % thread_id1)

        # wait MySQL server for disconnecting killed connection
        time.sleep(0.02)

        try:
            cursor1.execute('select 1')
        except MySQLdb.OperationalError:
            pass
        else:
            ok_(False, '%r connection did not break, it should be' % cursor1)

        cursor1.execute('select 1')
        eq_(cursor1.fetchone(), (1, ))
        err_msg = 'Thread id did not change after re-connect, it should be'
        ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
Ejemplo n.º 5
0
 def test_cozydb_cozycursor_fetchone_dict(self):
     cursor = CozyCursor(**self.db_args)
     cursor.execute('select 1 as name')
     eq_(cursor.fetchone(as_dict=True), {'name': 1})
Ejemplo n.º 6
0
 def test_cozydb_cozycursor(self):
     cursor = CozyCursor(**self.db_args)
     cursor.execute('select 1')
     eq_(cursor.fetchone(), (1,))
Ejemplo n.º 7
0
 def test_cozydb_cozycursor_fetchone_dict(self):
     cursor = CozyCursor(**self.db_args)
     cursor.execute('select 1 as name')
     eq_(cursor.fetchone(as_dict=True), {'name': 1})
Ejemplo n.º 8
0
 def test_cozydb_cozycursor(self):
     cursor = CozyCursor(**self.db_args)
     cursor.execute('select 1')
     eq_(cursor.fetchone(), (1, ))