33 Tests extract query state from running backend (including concurrent extracts)
44Copyright (c) 2016-2016, Postgres Professional
55'''
6+ from __future__ import print_function , division , absolute_import
67
8+ import os
9+ import sys
710import argparse
11+ import getpass
812import psycopg2
9- import sys
13+
14+ sys .path .append (os .path .dirname (os .path .abspath (__file__ )))
1015from test_cases import *
1116
1217class PasswordPromptAction (argparse .Action ):
@@ -34,50 +39,51 @@ class TeardownException(Exception): pass
3439 'drop table foo cascade' ,
3540 'drop table bar cascade' ,
3641 'drop extension pg_query_state cascade' ,
37- ]
42+ ]
3843
3944tests = [
40- test_deadlock ,
41- test_simple_query ,
42- test_concurrent_access ,
43- test_nested_call ,
44- test_trigger ,
45- test_costs ,
46- test_buffers ,
47- test_timing ,
48- test_formats ,
49- test_timing_buffers_conflicts ,
50- test_insert_on_conflict ,
51- ]
45+ test_deadlock ,
46+ test_simple_query ,
47+ test_concurrent_access ,
48+ test_nested_call ,
49+ test_trigger ,
50+ test_costs ,
51+ test_buffers ,
52+ test_timing ,
53+ test_formats ,
54+ test_timing_buffers_conflicts ,
55+ test_insert_on_conflict ,
56+ ]
5257
5358def setup (con ):
5459 ''' Creates pg_query_state extension, creates tables for tests, fills it with data '''
55- print 'setting up...'
60+ print ( 'setting up...' )
5661 try :
5762 cur = con .cursor ()
5863 for cmd in setup_cmd :
5964 cur .execute (cmd )
6065 con .commit ()
6166 cur .close ()
62- except Exception , e :
67+ except Exception as e :
6368 raise SetupException ('Setup failed: %s' % e )
64- print 'done!'
69+ print ( 'done!' )
6570
6671def teardown (con ):
6772 ''' Drops table and extension '''
68- print 'tearing down...'
73+ print ( 'tearing down...' )
6974 try :
7075 cur = con .cursor ()
7176 for cmd in teardown_cmd :
7277 cur .execute (cmd )
7378 con .commit ()
7479 cur .close ()
75- except Exception , e :
80+ except Exception as e :
7681 raise TeardownException ('Teardown failed: %s' % e )
77- print 'done!'
82+ print ( 'done!' )
7883
7984def main (config ):
8085 ''' Main test function '''
86+
8187 con = psycopg2 .connect (** config )
8288 setup (con )
8389
@@ -86,19 +92,27 @@ def main(config):
8692 descr = test .__doc__
8793 else :
8894 descr = 'test case %d' % (i + 1 )
89- print ("%s..." % descr ),; sys .stdout .flush ()
95+ print (("%s..." % descr ))
96+ sys .stdout .flush ()
9097 test (config )
91- print 'ok!'
98+ print ('ok!' )
99+
100+ if os .environ ['LEVEL' ] == 'stress' :
101+ print ('Starting stress test' )
102+ stress_test (config )
103+ print ('Stress finished successfully' )
92104
93105 teardown (con )
94106 con .close ()
95107
96108if __name__ == '__main__' :
97109 parser = argparse .ArgumentParser (description = 'Query state of running backends tests' )
110+
98111 parser .add_argument ('--host' , default = 'localhost' , help = 'postgres server host' )
99112 parser .add_argument ('--port' , type = int , default = 5432 , help = 'postgres server port' )
100113 parser .add_argument ('--user' , dest = 'user' , default = 'postgres' , help = 'user name' )
101114 parser .add_argument ('--database' , dest = 'database' , default = 'postgres' , help = 'database name' )
102115 parser .add_argument ('--password' , dest = 'password' , nargs = 0 , action = PasswordPromptAction , default = '' )
116+
103117 args = parser .parse_args ()
104118 main (args .__dict__ )
0 commit comments