Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2f8e82

Browse files
author
Maksim Milyutin
committed
Split common tests and tpc-ds stress test on different modules
And add option to run TPC-DS stress test separately.
1 parentba34af1 commitb2f8e82

File tree

4 files changed

+262
-309
lines changed

4 files changed

+262
-309
lines changed

‎tests/common.py‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
'''
2+
common.py
3+
Copyright (c) 2016-2019, Postgres Professional
4+
'''
5+
6+
importpsycopg2
7+
importpsycopg2.extensions
8+
importselect
9+
10+
# Some queries from TPC-DS may freeze or be even broken,
11+
# so we allow some sort of failure, since we do not test
12+
# Postgres, but rather that pg_query_state do not crash
13+
# anything under stress load.
14+
MAX_PG_QS_RETRIES=50
15+
16+
17+
defwait(conn):
18+
"""wait for some event on connection to postgres"""
19+
while1:
20+
state=conn.poll()
21+
ifstate==psycopg2.extensions.POLL_OK:
22+
break
23+
elifstate==psycopg2.extensions.POLL_WRITE:
24+
select.select([], [conn.fileno()], [])
25+
elifstate==psycopg2.extensions.POLL_READ:
26+
select.select([conn.fileno()], [], [])
27+
else:
28+
raisepsycopg2.OperationalError("poll() returned %s"%state)
29+
30+
defn_async_connect(config,n=1):
31+
"""establish n asynchronious connections to the postgres with specified config"""
32+
33+
aconfig=config.copy()
34+
aconfig['async']=True
35+
36+
result= []
37+
for_inrange(n):
38+
conn=psycopg2.connect(**aconfig)
39+
wait(conn)
40+
result.append(conn)
41+
returnresult
42+
43+
defn_close(conns):
44+
"""close connections to postgres"""
45+
46+
forconninconns:
47+
conn.close()
48+
49+
defpg_query_state(config,pid,verbose=False,costs=False,timing=False, \
50+
buffers=False,triggers=False,format='text', \
51+
stress_in_progress=False):
52+
"""
53+
Get query state from backend with specified pid and optional parameters.
54+
Save any warning, info, notice and log data in global variable 'notices'
55+
"""
56+
57+
conn=psycopg2.connect(**config)
58+
curs=conn.cursor()
59+
60+
ifstress_in_progress:
61+
set_guc(conn,'statement_timeout',TPC_DS_STATEMENT_TIMEOUT)
62+
n_retries=0
63+
64+
result= []
65+
whilenotresult:
66+
curs.callproc('pg_query_state', (pid,verbose,costs,timing,buffers,triggers,format))
67+
result=curs.fetchall()
68+
69+
ifstress_in_progress:
70+
n_retries+=1
71+
ifn_retries>=MAX_PG_QS_RETRIES:
72+
print('\npg_query_state tried %s times with no effect, giving up'%MAX_PG_QS_RETRIES)
73+
break
74+
75+
notices=conn.notices[:]
76+
conn.close()
77+
returnresult,notices
78+
79+
defquery_state(config,async_conn,query,args={},num_workers=0,stress_in_progress=False):
80+
"""
81+
Get intermediate state of 'query' on connection 'async_conn' after number of 'steps'
82+
of node executions from start of query
83+
"""
84+
85+
acurs=async_conn.cursor()
86+
conn=psycopg2.connect(**config)
87+
curs=conn.cursor()
88+
89+
set_guc(async_conn,'enable_mergejoin','off')
90+
set_guc(async_conn,'max_parallel_workers_per_gather',num_workers)
91+
acurs.execute(query)
92+
93+
# extract current state of query progress
94+
pg_qs_args= {
95+
'config':config,
96+
'pid':async_conn.get_backend_pid()
97+
}
98+
fork,vinargs.items():
99+
pg_qs_args[k]=v
100+
result,notices=pg_query_state(**pg_qs_args)
101+
wait(async_conn)
102+
103+
set_guc(async_conn,'pg_query_state.executor_trace','off')
104+
set_guc(async_conn,'enable_mergejoin','on')
105+
106+
conn.close()
107+
returnresult,notices
108+
109+
defset_guc(async_conn,param,value):
110+
acurs=async_conn.cursor()
111+
acurs.execute('set %s to %s'% (param,value))
112+
wait(async_conn)

‎tests/pg_qs_test_runner.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'''
2-
pg_qs_test_cases.py
3-
Tests extract query state from running backend (including concurrent extracts)
4-
Copyright (c) 2016-2016, Postgres Professional
2+
pg_qs_test_runner.py
3+
Copyright (c) 2016-2019, Postgres Professional
54
'''
65

7-
importos
8-
importsys
96
importargparse
107
importgetpass
8+
importos
119
importpsycopg2
10+
importsys
1211

1312
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
1413
fromtest_casesimport*
14+
importtpcds
1515

1616
classPasswordPromptAction(argparse.Action):
1717
def__call__(self,parser,args,values,option_string=None):
@@ -88,7 +88,7 @@ def main(config):
8888

8989
ifconfig.use_tpcds:
9090
print('Starting stress test')
91-
test_tpc_ds(conn_params)
91+
tpcds.test_tpc_ds(conn_params)
9292
print('Stress finished successfully')
9393
return
9494

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp