~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to tests/databases/postgres.py

  • Committer: James Henstridge
  • Date: 2009-07-30 06:19:27 UTC
  • mfrom: (314.2.3 bug-374909)
  • Revision ID: james@jamesh.id.au-20090730061927-u5t645zrprpec6gu
(Guilherme Salgado) Further fixes to disconnection handling.

If the connection had been disconnected outside of the control of Storm, 
the error raised during a Connection.rollback() call was not being 
interpreted as a disconnection error on PostgreSQL.
[r=jkakar, jamesh] [f=374909]

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from storm.databases.postgres import (
25
25
    Postgres, compile, currval, Returning, PostgresTimeoutTracer)
26
26
from storm.database import create_database
27
 
from storm.exceptions import ProgrammingError
 
27
from storm.exceptions import InterfaceError, ProgrammingError
28
28
from storm.variables import DateTimeVariable, RawStrVariable
29
29
from storm.variables import ListVariable, IntVariable, Variable
30
30
from storm.properties import Int
526
526
    host_environment_variable = "STORM_POSTGRES_HOST_URI"
527
527
    default_port = 5432
528
528
 
 
529
    def test_rollback_swallows_InterfaceError(self):
 
530
        """Test that InterfaceErrors get caught on rollback().
 
531
 
 
532
        InterfaceErrors are a form of a disconnection error, so rollback()
 
533
        must swallow them and reconnect.
 
534
        """
 
535
        class FakeConnection:
 
536
            def rollback(self):
 
537
                raise InterfaceError('connection already closed')
 
538
        self.connection._raw_connection = FakeConnection()
 
539
        try:
 
540
            self.connection.rollback()
 
541
        except Exception, exc:
 
542
            self.fail('Exception should have been swallowed: %s' % repr(exc))
 
543
 
529
544
 
530
545
class PostgresTimeoutTracerTest(TimeoutTracerTestBase):
531
546