Skip to content

Commit 3dfe998

Browse files
Move python test on testgres and add stress test
1 parent 91e3196 commit 3dfe998

8 files changed

+5182
-301
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
- PG_VERSION=10
2525
- PG_VERSION=9.6 LEVEL=hardcore
2626
- PG_VERSION=9.6
27+
- PG_VERSION=10 LEVEL=stress
2728

2829
matrix:
2930
allow_failures:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DATA_built = $(EXTENSION)--$(EXTVERSION).sql
99
PGFILEDESC = "pg_query_state - facility to track progress of plan execution"
1010

1111
EXTRA_CLEAN = ./isolation_output $(EXTENSION)--$(EXTVERSION).sql \
12-
Dockerfile ./tests/*.pyc
12+
Dockerfile ./tests/*.pyc ./tmp_stress
1313

1414
ifdef USE_PGXS
1515
PG_CONFIG = pg_config

README.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ Done!
3434
## Tests
3535
Tests using parallel sessions using python 2.7 script:
3636
```
37+
export PG_CONFIG=/path/to/pg_config
3738
python tests/pg_qs_test_runner.py [OPTION]...
3839
```
3940
*prerequisite packages*:
40-
* `psycopg2` version 2.6 or later
41+
* `testgres` version 1.8.2 or later
4142
* `PyYAML` version 3.11 or later
42-
43+
4344
*options*:
44-
* *- -host* --- postgres server host, default value is *localhost*
45-
* *- -port* --- postgres server port, default value is *5432*
46-
* *- -database* --- database name, default value is *postgres*
47-
* *- -user* --- user name, default value is *postgres*
48-
* *- -password* --- user's password, default value is empty
45+
* *--stress* --- run stress test using tpc-ds benchmark
4946

5047
## Function pg\_query\_state
5148
```plpgsql

run_tests.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# * scan-build
99
# * hardcore
1010
# * nightmare
11+
# * stress
1112
#
1213

1314
set -ux
@@ -146,7 +147,11 @@ set +x -e
146147
virtualenv /tmp/env && source /tmp/env/bin/activate &&
147148
pip install PyYAML && pip install psycopg2
148149
set -e #exit virtualenv with error code
149-
python tests/pg_qs_test_runner.py --port $PGPORT
150+
if [ "$LEVEL" = "stress" ]; then
151+
python tests/pg_qs_test_runner.py --stress
152+
else
153+
python tests/pg_qs_test_runner.py
154+
fi
150155
deactivate
151156
set -x
152157

tests/pg_qs_test_runner.py

+25-44
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
'''
66

77
import argparse
8-
import psycopg2
98
import sys
109
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
1611

1712
class SetupException(Exception): pass
18-
class TeardownException(Exception): pass
1913

2014
setup_cmd = [
2115
'drop extension if exists pg_query_state cascade',
@@ -25,17 +19,11 @@ class TeardownException(Exception): pass
2519
'create table foo(c1 integer, c2 text)',
2620
'create table bar(c1 integer, c2 boolean)',
2721
'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',
2923
'analyze foo',
3024
'analyze bar',
3125
]
3226

33-
teardown_cmd = [
34-
'drop table foo cascade',
35-
'drop table bar cascade',
36-
'drop extension pg_query_state cascade',
37-
]
38-
3927
tests = [
4028
test_deadlock,
4129
test_simple_query,
@@ -50,55 +38,48 @@ class TeardownException(Exception): pass
5038
test_insert_on_conflict,
5139
]
5240

53-
def setup(con):
41+
def setup(node):
5442
''' Creates pg_query_state extension, creates tables for tests, fills it with data '''
5543
print 'setting up...'
44+
conn = testgres.connection.NodeConnection(node)
5645
try:
57-
cur = con.cursor()
5846
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()
6250
except Exception, e:
6351
raise SetupException('Setup failed: %s' % e)
6452
print 'done!'
6553

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):
8055
''' 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)
8361

8462
for i, test in enumerate(tests):
8563
if test.__doc__:
8664
descr = test.__doc__
8765
else:
8866
descr = 'test case %d' % (i+1)
8967
print ("%s..." % descr),; sys.stdout.flush()
90-
test(config)
68+
test(node)
9169
print 'ok!'
9270

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()
9579

9680
if __name__ == '__main__':
9781
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")
10384
args = parser.parse_args()
104-
main(args.__dict__)
85+
main(args)

tests/prepare_stress.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
mkdir -p tmp_stress
3+
cd tmp_stress
4+
rm -rf ./*
5+
git clone https://github.com/gregrahn/tpcds-kit.git
6+
cd tpcds-kit/tools
7+
make -s
8+
9+
#Generate data
10+
./dsdgen -FORCE -VERBOSE
11+
mkdir tables -p
12+
#Prepare data
13+
for i in `ls *.dat`; do
14+
echo "Prepare file " $i
15+
sed 's/|$//' $i > tables/$i
16+
done
17+
#Generate queries
18+
./dsqgen -DIRECTORY ../query_templates -INPUT ../query_templates/templates.lst \
19+
-VERBOSE Y -QUALIFY Y -DIALECT netezza

0 commit comments

Comments
 (0)