# HG changeset patch # User Julien Cristau # Date 1399364903 -7200 # Node ID ad0615d4500d110dabbf7d2d7e7735ab4c502a54 # Parent 20f45a9b385ca163b0b4d6ac5e3ca67c81090b19 [server/test] Add a test for db-statement-timeout option Sadly I don't think there's a way to test that functionality without adding sleeps which make the test suite longer :/ Related to #2547026 diff -r 20f45a9b385c -r ad0615d4500d server/test/unittest_postgres.py --- a/server/test/unittest_postgres.py Wed Mar 05 13:51:28 2014 +0100 +++ b/server/test/unittest_postgres.py Tue May 06 10:28:23 2014 +0200 @@ -28,8 +28,14 @@ from unittest_querier import FixedOffset +class PostgresTimeoutConfiguration(PostgresApptestConfiguration): + default_sources = PostgresApptestConfiguration.default_sources.copy() + default_sources['system'] = PostgresApptestConfiguration.default_sources['system'].copy() + default_sources['system']['db-statement-timeout'] = 200 + + class PostgresFTITC(CubicWebTC): - configcls = PostgresApptestConfiguration + configcls = PostgresTimeoutConfiguration def test_eid_range(self): # concurrent allocation of eid ranges @@ -131,6 +137,13 @@ yield self.assertEqual, sql("SELECT limit_size('a>b', 'text/html', 2)"), \ 'a>...' + def test_statement_timeout(self): + with self.admin_access.repo_cnx() as cnx: + cnx.system_sql('select pg_sleep(0.1)') + with self.assertRaises(Exception): + cnx.system_sql('select pg_sleep(0.3)') + + if __name__ == '__main__': from logilab.common.testlib import unittest_main unittest_main()