psycopg2/tests
Greg Ward b203a7c775 Always detect when a connection is closed behind psycopg2's back.
There's a race condition that only seems to happen over Unix-domain
sockets. Sometimes, the closed socket is reported by the kernel to
libpq like this (captured with strace):

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = 29
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, 0x12d0330, 16384, 0, 0, 0)  = -1 ECONNRESET (Connection reset by peer)

That is, psycopg2/libpq sees no error when sending the first query
after the connection is closed, but gets an error reading the result.
In that case, everything worked fine.

But sometimes, the error manifests like this:

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe)
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0

i.e. libpq received an error when sending the query. This manifests as
a slightly different exception from a slightly different place. More
importantly, in this case connection.closed is left at 0 rather than
being set to 2, and that is the bug I'm fixing here.

Note that we see almost identical behaviour for sync and async
connections, and the fixes are the same. So I added extremely similar
test cases.

Finally, there is still a bug here: for async connections, we
sometimes raise DatabaseError (incorrect) and sometimes raise
OperationalError (correct). Will fix that next.
2017-03-14 12:08:03 +00:00
..
__init__.py Merge branch 'master' into sql-compose 2017-02-03 04:56:02 +00:00
dbapi20_tpc.py hook up two phase commit tests. 2010-11-05 09:34:47 +00:00
dbapi20.py Fix several typos 2015-05-03 10:30:21 +01:00
test_async_keyword.py Added readonly and deferrable attributes 2017-02-16 12:46:35 +00:00
test_async.py Added readonly and deferrable attributes 2017-02-16 12:46:35 +00:00
test_bug_gc.py Python source cleanup using flake8 2016-10-11 00:11:55 +01:00
test_bugX000.py Python source cleanup using flake8 2016-10-11 00:11:55 +01:00
test_cancel.py Work around a race condition in async cancel test 2017-02-06 21:40:05 +00:00
test_connection.py Ignore None arguments passed to make_dsn() 2017-03-01 20:12:13 +00:00
test_copy.py Further skipping of slow tests 2017-02-02 03:02:29 +00:00
test_cursor.py Always detect when a connection is closed behind psycopg2's back. 2017-03-14 12:08:03 +00:00
test_dates.py Skip test on PG version with bad interval rounding 2017-03-01 02:14:35 +00:00
test_errcodes.py Merge branch 'async-keyword' 2017-02-03 04:45:17 +00:00
test_extras_dictcursor.py Python source cleanup using flake8 2016-10-11 00:11:55 +01:00
test_fast_executemany.py Skipped a couple of tests failing on old dbs 2017-02-06 21:40:05 +00:00
test_green.py Allow skipping the slow test 2017-02-02 01:53:50 +00:00
test_ipaddress.py Skip tests with server not supporting NULL in array 2017-02-06 21:40:05 +00:00
test_lobject.py Further skipping of slow tests 2017-02-02 03:02:29 +00:00
test_module.py assertDsnEqual moved as TestSuite method 2017-02-06 21:40:05 +00:00
test_notify.py Further skipping of slow tests 2017-02-02 03:02:29 +00:00
test_psycopg2_dbapi20.py Merge branch 'master' into named-callproc 2016-12-26 01:49:42 +01:00
test_quote.py Skipped a couple of tests failing on old dbs 2017-02-06 21:40:05 +00:00
test_replication.py Added async_ as an alias for async 2017-02-03 04:43:49 +00:00
test_sql.py Deal consistently with E'' quotes in tests 2017-02-06 21:40:05 +00:00
test_transaction.py Allow skipping the slow test 2017-02-02 01:53:50 +00:00
test_types_basic.py Don't convert '{}'::unknown into an empty list 2017-02-08 08:43:53 +00:00
test_types_extras.py Deal consistently with E'' quotes in tests 2017-02-06 21:40:05 +00:00
test_with.py Python source cleanup using flake8 2016-10-11 00:11:55 +01:00
testconfig.py Test moved to the right module, cleanup, but same problem 2016-07-01 18:01:16 +01:00
testutils.py Skip the tests according to the earliest of libpq built/linked. 2017-03-02 19:32:44 +00:00