Skip to content

Commit 957d83f

Browse files
committed
Transfer tests to python3
1 parent 0ebe691 commit 957d83f

8 files changed

+194
-75
lines changed

Dockerfile.tmpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apk add --no-cache \
77
make musl-dev gcc bison flex coreutils \
88
zlib-dev libedit-dev \
99
clang clang-analyzer linux-headers \
10-
python2 python2-dev py2-virtualenv;
10+
python3 python3-dev py3-virtualenv;
1111

1212

1313
# Install fresh valgrind
@@ -29,6 +29,7 @@ RUN chown postgres:postgres ${PGDATA} && \
2929
chmod a+rwx /usr/local/share/postgresql/extension
3030

3131
COPY run_tests.sh /run.sh
32+
COPY tests/requirements.txt /requirements.txt
3233
RUN chmod 755 /run.sh
3334

3435
ADD . /pg/testdir

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

mk_dockerfile.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env sh
2+
13
if [ -z ${PG_VERSION+x} ]; then
24
echo PG_VERSION is not set!
35
exit 1

run_tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ if [ -f regression.diffs ]; then cat regression.diffs; fi
143143

144144
# run python tests
145145
set +x -e
146-
virtualenv /tmp/env && source /tmp/env/bin/activate &&
147-
pip install PyYAML && pip install psycopg2
146+
python3 -m venv /tmp/env && source /tmp/env/bin/activate &&
147+
pip install -r /requirements.txt
148148
set -e #exit virtualenv with error code
149149
python tests/pg_qs_test_runner.py --port $PGPORT
150150
deactivate

tests/pg_qs_test_runner.py

+36-22
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
Tests extract query state from running backend (including concurrent extracts)
44
Copyright (c) 2016-2016, Postgres Professional
55
'''
6+
from __future__ import print_function, division, absolute_import
67

8+
import os
9+
import sys
710
import argparse
11+
import getpass
812
import psycopg2
9-
import sys
13+
14+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
1015
from test_cases import *
1116

1217
class 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

3944
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+
]
5257

5358
def 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

6671
def 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

7984
def 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

96108
if __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__)

tests/prepare_stress.sh

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

tests/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PyYAML
2+
psycopg2
3+
progressbar2

0 commit comments

Comments
 (0)