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

Commitcf22c51

Browse files
author
Artur Zakirov
committed
Added tests using testgres framework
1 parent344d1c0 commitcf22c51

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

‎.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
.deps
22
*.o
33
*.so
4-
results
4+
results
5+
__pycache__
6+
*.pyc
7+
8+
# virtualenv
9+
bin
10+
include
11+
lib
12+
pip-selfcheck.json
13+

‎tests/__init__.py

Whitespace-only changes.

‎tests/pglist_tests.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#coding: utf-8
2+
"""
3+
Test RUM index with big base 'pglist'
4+
5+
Copyright (c) 2015-2016, Postgres Professional
6+
"""
7+
importunittest
8+
importos
9+
importsys
10+
importgzip
11+
importtestgresastg
12+
13+
ifsys.version_info[0]<3:
14+
importurllibasrequest
15+
else:
16+
importurllib.requestasrequest
17+
18+
fromos.pathimportexpanduser
19+
20+
classPglistTests(unittest.TestCase):
21+
defsetUp(self):
22+
self.node=tg.get_new_node("pglist_select")
23+
try:
24+
self.node.init()
25+
self.node.append_conf("postgresql.conf",
26+
"shared_buffers='4GB'\n"
27+
"maintenance_work_mem='2GB'\n"
28+
"max_wal_size='2GB'\n"
29+
"work_mem='50MB'")
30+
self.node.start()
31+
32+
self.init_pglist_data(self.node)
33+
exceptExceptionase:
34+
self.printlog(self.node.logs_dir+"/postgresql.log")
35+
raisee
36+
37+
deftearDown(self):
38+
tg.stop_all()
39+
40+
definit_pglist_data(self,node):
41+
# Check if 'pglist' base exists
42+
base_exists=False
43+
bases=node.execute("postgres","SELECT datname FROM pg_database")
44+
forbaseinbases:
45+
ifbase[0].lower()=="pglist":
46+
base_exists=True
47+
break
48+
49+
ifbase_exists:
50+
return
51+
52+
# Check if 'pglist' dump exists
53+
home=expanduser("~")
54+
pglist_dump=os.path.join(home,"pglist-28-04-16.dump")
55+
ifnotos.path.isfile(pglist_dump):
56+
pglist_dumpgz=pglist_dump+".gz"
57+
ifnotos.path.isfile(pglist_dumpgz):
58+
print("Downloading: %s"%pglist_dumpgz)
59+
request.urlretrieve("http://www.sai.msu.su/~megera/postgres/files/pglist-28-04-16.dump.gz",
60+
pglist_dumpgz)
61+
62+
print("Decompressing: %s"%pglist_dumpgz)
63+
gz=gzip.open(pglist_dumpgz,'rb')
64+
withopen(pglist_dump,'wb')asf:
65+
f.write(gz.read())
66+
67+
os.remove(pglist_dumpgz)
68+
69+
# Restore dump file
70+
print("Restoring 'pglist'")
71+
node.safe_psql("postgres","CREATE DATABASE pglist")
72+
node.psql("pglist",filename=pglist_dump)
73+
74+
node.safe_psql("pglist","CREATE EXTENSION rum")
75+
76+
defprintlog(self,logfile):
77+
withopen(logfile,'r')aslog:
78+
forlineinlog.readlines():
79+
print(line)
80+
81+
deftest_order_by(self):
82+
"""Tests SELECT constructions to 'pglist' base"""
83+
try:
84+
print("Creating index 'rumidx_orderby_sent'")
85+
86+
self.node.safe_psql("pglist",
87+
"CREATE INDEX rumidx_orderby_sent ON pglist USING rum ("
88+
" fts rum_tsvector_timestamp_ops, sent) "
89+
" WITH (attach=sent, to=fts, order_by_attach=t)")
90+
91+
print("Running tests")
92+
93+
self.assertEqual(
94+
self.node.safe_psql(
95+
"pglist",
96+
"SELECT sent, subject "
97+
" FROM pglist "
98+
" WHERE fts @@ to_tsquery('english', 'backend <-> crushed') "
99+
" ORDER BY sent <=| '2016-01-01 00:01' LIMIT 5"
100+
),
101+
b'1999-06-02 11:52:46|Re: [HACKERS] PID of backend\n'
102+
)
103+
104+
self.assertEqual(
105+
self.node.safe_psql(
106+
"pglist",
107+
"SELECT count(*) FROM pglist WHERE fts @@ to_tsquery('english', 'tom & lane')"
108+
),
109+
b'222813\n'
110+
)
111+
exceptExceptionase:
112+
self.printlog(self.node.logs_dir+"/postgresql.log")
113+
raisee
114+
115+
if__name__=="__main__":
116+
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp