[server/test] Add a test for db-statement-timeout option
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 06 May 2014 10:28:23 +0200
changeset 10455 ad0615d4500d
parent 10454 20f45a9b385c
child 10479 b0417cacecd9
[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
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('<span>a>b</span>', '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()