5
5
'''
6
6
7
7
import argparse
8
- import psycopg2
9
8
import sys
10
9
from test_cases import *
11
-
12
- class PasswordPromptAction (argparse .Action ):
13
- def __call__ (self , parser , args , values , option_string = None ):
14
- password = getpass .getpass ()
15
- setattr (args , self .dest , password )
10
+ import testgres
16
11
17
12
class SetupException (Exception ): pass
18
- class TeardownException (Exception ): pass
19
13
20
14
setup_cmd = [
21
15
'drop extension if exists pg_query_state cascade' ,
@@ -25,17 +19,11 @@ class TeardownException(Exception): pass
25
19
'create table foo(c1 integer, c2 text)' ,
26
20
'create table bar(c1 integer, c2 boolean)' ,
27
21
'insert into foo select i, md5(random()::text) from generate_series(1, 1000000) as i' ,
28
- 'insert into bar select i, i%2=1 from generate_series(1, 500000) as i' ,
22
+ 'insert into bar select i, i%% 2=1 from generate_series(1, 500000) as i' ,
29
23
'analyze foo' ,
30
24
'analyze bar' ,
31
25
]
32
26
33
- teardown_cmd = [
34
- 'drop table foo cascade' ,
35
- 'drop table bar cascade' ,
36
- 'drop extension pg_query_state cascade' ,
37
- ]
38
-
39
27
tests = [
40
28
test_deadlock ,
41
29
test_simple_query ,
@@ -50,55 +38,48 @@ class TeardownException(Exception): pass
50
38
test_insert_on_conflict ,
51
39
]
52
40
53
- def setup (con ):
41
+ def setup (node ):
54
42
''' Creates pg_query_state extension, creates tables for tests, fills it with data '''
55
43
print 'setting up...'
44
+ conn = testgres .connection .NodeConnection (node )
56
45
try :
57
- cur = con .cursor ()
58
46
for cmd in setup_cmd :
59
- cur .execute (cmd )
60
- con .commit ()
61
- cur .close ()
47
+ conn .execute (cmd )
48
+ conn .commit ()
49
+ conn .close ()
62
50
except Exception , e :
63
51
raise SetupException ('Setup failed: %s' % e )
64
52
print 'done!'
65
53
66
- def teardown (con ):
67
- ''' Drops table and extension '''
68
- print 'tearing down...'
69
- try :
70
- cur = con .cursor ()
71
- for cmd in teardown_cmd :
72
- cur .execute (cmd )
73
- con .commit ()
74
- cur .close ()
75
- except Exception , e :
76
- raise TeardownException ('Teardown failed: %s' % e )
77
- print 'done!'
78
-
79
- def main (config ):
54
+ def main (args ):
80
55
''' Main test function '''
81
- con = psycopg2 .connect (** config )
82
- setup (con )
56
+ node = testgres .get_new_node ()
57
+ node .init ()
58
+ node .append_conf ("shared_preload_libraries='pg_query_state'\n " )
59
+ node .start ()
60
+ setup (node )
83
61
84
62
for i , test in enumerate (tests ):
85
63
if test .__doc__ :
86
64
descr = test .__doc__
87
65
else :
88
66
descr = 'test case %d' % (i + 1 )
89
67
print ("%s..." % descr ),; sys .stdout .flush ()
90
- test (config )
68
+ test (node )
91
69
print 'ok!'
92
70
93
- teardown (con )
94
- con .close ()
71
+ if args .stress :
72
+ print 'Start stress test'
73
+ stress_test (node )
74
+ print 'Start stress finished successfully'
75
+ print 'stop'
76
+
77
+ node .stop ()
78
+ node .cleanup ()
95
79
96
80
if __name__ == '__main__' :
97
81
parser = argparse .ArgumentParser (description = 'Query state of running backends tests' )
98
- parser .add_argument ('--host' , default = 'localhost' , help = 'postgres server host' )
99
- parser .add_argument ('--port' , type = int , default = 5432 , help = 'postgres server port' )
100
- parser .add_argument ('--user' , dest = 'user' , default = 'postgres' , help = 'user name' )
101
- parser .add_argument ('--database' , dest = 'database' , default = 'postgres' , help = 'database name' )
102
- parser .add_argument ('--password' , dest = 'password' , nargs = 0 , action = PasswordPromptAction , default = '' )
82
+ parser .add_argument ('--stress' , help = 'run stress test using tpc-ds benchmark' ,
83
+ action = "store_true" )
103
84
args = parser .parse_args ()
104
- main (args . __dict__ )
85
+ main (args )
0 commit comments