3
3
Tests extract query state from running backend (including concurrent extracts)
4
4
Copyright (c) 2016-2016, Postgres Professional
5
5
'''
6
+ from __future__ import print_function , division , absolute_import
6
7
8
+ import os
9
+ import sys
7
10
import argparse
11
+ import getpass
8
12
import psycopg2
9
- import sys
13
+
14
+ sys .path .append (os .path .dirname (os .path .abspath (__file__ )))
10
15
from test_cases import *
11
16
12
17
class PasswordPromptAction (argparse .Action ):
@@ -34,50 +39,51 @@ class TeardownException(Exception): pass
34
39
'drop table foo cascade' ,
35
40
'drop table bar cascade' ,
36
41
'drop extension pg_query_state cascade' ,
37
- ]
42
+ ]
38
43
39
44
tests = [
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
+ ]
52
57
53
58
def setup (con ):
54
59
''' Creates pg_query_state extension, creates tables for tests, fills it with data '''
55
- print 'setting up...'
60
+ print ( 'setting up...' )
56
61
try :
57
62
cur = con .cursor ()
58
63
for cmd in setup_cmd :
59
64
cur .execute (cmd )
60
65
con .commit ()
61
66
cur .close ()
62
- except Exception , e :
67
+ except Exception as e :
63
68
raise SetupException ('Setup failed: %s' % e )
64
- print 'done!'
69
+ print ( 'done!' )
65
70
66
71
def teardown (con ):
67
72
''' Drops table and extension '''
68
- print 'tearing down...'
73
+ print ( 'tearing down...' )
69
74
try :
70
75
cur = con .cursor ()
71
76
for cmd in teardown_cmd :
72
77
cur .execute (cmd )
73
78
con .commit ()
74
79
cur .close ()
75
- except Exception , e :
80
+ except Exception as e :
76
81
raise TeardownException ('Teardown failed: %s' % e )
77
- print 'done!'
82
+ print ( 'done!' )
78
83
79
84
def main (config ):
80
85
''' Main test function '''
86
+
81
87
con = psycopg2 .connect (** config )
82
88
setup (con )
83
89
@@ -86,19 +92,27 @@ def main(config):
86
92
descr = test .__doc__
87
93
else :
88
94
descr = 'test case %d' % (i + 1 )
89
- print ("%s..." % descr ),; sys .stdout .flush ()
95
+ print (("%s..." % descr ))
96
+ sys .stdout .flush ()
90
97
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' )
92
104
93
105
teardown (con )
94
106
con .close ()
95
107
96
108
if __name__ == '__main__' :
97
109
parser = argparse .ArgumentParser (description = 'Query state of running backends tests' )
110
+
98
111
parser .add_argument ('--host' , default = 'localhost' , help = 'postgres server host' )
99
112
parser .add_argument ('--port' , type = int , default = 5432 , help = 'postgres server port' )
100
113
parser .add_argument ('--user' , dest = 'user' , default = 'postgres' , help = 'user name' )
101
114
parser .add_argument ('--database' , dest = 'database' , default = 'postgres' , help = 'database name' )
102
115
parser .add_argument ('--password' , dest = 'password' , nargs = 0 , action = PasswordPromptAction , default = '' )
116
+
103
117
args = parser .parse_args ()
104
118
main (args .__dict__ )
0 commit comments