Fix stop_replication: always raise outside the loop.

This commit is contained in:
Oleksandr Shulgin 2015-10-14 12:50:08 +02:00
parent 54079072db
commit fea2260fc5
2 changed files with 14 additions and 2 deletions

View File

@ -1624,8 +1624,6 @@ psyco_curs_start_replication_expert(cursorObject *self, PyObject *args, PyObject
Py_INCREF(res);
}
self->repl_started = 1;
return res;
}
@ -1676,6 +1674,8 @@ psyco_curs_consume_replication_stream(cursorObject *self, PyObject *args, PyObje
return NULL;
}
self->repl_started = 1;
if (pq_copy_both(self, consumer, decode, keepalive_interval) >= 0) {
res = Py_None;
Py_INCREF(res);

View File

@ -1197,6 +1197,18 @@ class ReplicationTest(ConnectingTestCase):
cur.execute("IDENTIFY_SYSTEM")
cur.fetchall()
@skip_before_postgres(9, 0)
def test_stop_replication_raises(self):
import psycopg2.extras
conn = self.repl_connect(connection_factory=psycopg2.extras.PhysicalReplicationConnection)
if conn is None: return
cur = conn.cursor()
self.assertRaises(psycopg2.ProgrammingError, cur.stop_replication)
cur.start_replication()
self.assertRaises(psycopg2.ProgrammingError, cur.stop_replication)
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)