Re: closing a connection from "outside" an application (for testing)

Stuart Bishop <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Webb Sprague wrote:
> Hi all,
> 
> I have a mod_python web-app that connects to a database and every once
> in a while has closed the connection when I try to get a cursor; now I
> have code that tests for "conn.closed" and reopens if necessary before
> returning the cursor.
> 
> My question:  is there some way to get the connection to close (on
> purpose) in order to test the code that reopens the connection?

Two methods I'm aware of:

1) Open a new connection to the database, get the process id of the
connection you want to die (select procpid from pg_stat_activity where
[...]), and kill that process using a stored procedure (or os.kill if your
running your tests as a unix user with relevant permissions).

2) Make psycopg connect to a tcp proxy rather than directly to PostgreSQL.
Kill the proxy and restart it.

Ideally you want to test both cases - the first will be what your app sees
when the database kills your connection and it will be terminated somewhat
nicely. The second case is what your app sees when the network connection dies.

-- 
Stuart Bishop <[email protected]>
http://www.stuartbishop.net/

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHfbOMAfqZj7rGN0oRApzwAJoC+mBr92SVgcXDGzPQ9evQrQREFACdES+f
kOCmyyjWPwX1GbIQxFKoKJM=
=DKck
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.