Skip to content

Commit fc552f2

Browse files
author
Artur Zakirov
committed
Update tests. Use specified directory 'tmp_install'
1 parent 3283aed commit fc552f2

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
results
55
__pycache__
66
*.pyc
7+
tmp_install
78

89
# virtualenv
910
bin

tests/pglist_tests.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
class PglistTests(unittest.TestCase):
2222

2323
def setUp(self):
24-
self.node = tg.get_new_node("pglist_select")
24+
current_dir = os.path.dirname(os.path.abspath(__file__))
25+
26+
self.node = tg.get_new_node("pglist",
27+
os.path.join(current_dir, "tmp_install"))
2528
try:
2629
self.node.init()
2730
self.node.append_conf("postgresql.conf",
@@ -30,26 +33,20 @@ def setUp(self):
3033
"max_wal_size='2GB'\n"
3134
"work_mem='50MB'")
3235
self.node.start()
33-
34-
self.init_pglist_data(self.node)
3536
except Exception as e:
36-
self.printlog(self.node.logs_dir + "/postgresql.log")
37+
self.printlog(os.path.join(self.node.logs_dir, "postgresql.log"))
3738
raise e
3839

3940
def tearDown(self):
4041
tg.stop_all()
4142

4243
def init_pglist_data(self, node):
4344
# Check if 'pglist' base exists
44-
base_exists = False
4545
bases = node.execute("postgres",
46-
"SELECT datname FROM pg_database WHERE datistemplate = false")
47-
for base in bases:
48-
if base[0].lower() == "pglist":
49-
base_exists = True
50-
break
51-
52-
if base_exists:
46+
"SELECT count(*) FROM pg_database "
47+
"WHERE datistemplate = false AND "
48+
" datname = 'pglist'")
49+
if bases[0][0] != 0:
5350
return
5451

5552
# Check if 'pglist' dump exists
@@ -58,12 +55,12 @@ def init_pglist_data(self, node):
5855
if not os.path.isfile(pglist_dump):
5956
pglist_dumpgz = pglist_dump + ".gz"
6057
if not os.path.isfile(pglist_dumpgz):
61-
print("Downloading: %s" % pglist_dumpgz)
58+
print("Downloading: {0}".format(pglist_dumpgz))
6259
request.urlretrieve(
6360
"http://www.sai.msu.su/~megera/postgres/files/pglist-28-04-16.dump.gz",
6461
pglist_dumpgz)
6562

66-
print("Decompressing: %s" % pglist_dumpgz)
63+
print("Decompressing: {0}".format(pglist_dumpgz))
6764
gz = gzip.open(pglist_dumpgz, 'rb')
6865
with open(pglist_dump, 'wb') as f:
6966
f.write(gz.read())
@@ -85,13 +82,22 @@ def printlog(self, logfile):
8582
def test_order_by(self):
8683
"""Tests SELECT constructions to 'pglist' base"""
8784
try:
88-
print("Creating index 'rumidx_orderby_sent'")
89-
90-
self.node.safe_psql(
85+
self.init_pglist_data(self.node)
86+
indexes = self.node.execute(
9187
"pglist",
92-
"CREATE INDEX rumidx_orderby_sent ON pglist USING rum ("
93-
" fts rum_tsvector_timestamp_ops, sent) "
94-
" WITH (attach=sent, to=fts, order_by_attach=t)")
88+
"SELECT count(*) FROM pg_class c "
89+
" JOIN pg_index i ON i.indexrelid = c.oid"
90+
" JOIN pg_class c2 ON i.indrelid = c2.oid"
91+
" WHERE c.relkind = 'i' AND c2.relname = 'pglist' AND "
92+
" c.relname = 'rumidx_orderby_sent'")
93+
if indexes[0][0] == 0:
94+
print("Creating index 'rumidx_orderby_sent'")
95+
96+
self.node.safe_psql(
97+
"pglist",
98+
"CREATE INDEX rumidx_orderby_sent ON pglist USING rum ("
99+
" fts rum_tsvector_timestamp_ops, sent) "
100+
" WITH (attach=sent, to=fts, order_by_attach=t)")
95101

96102
print("Running tests")
97103

@@ -100,7 +106,8 @@ def test_order_by(self):
100106
"pglist",
101107
"SELECT sent, subject "
102108
" FROM pglist "
103-
" WHERE fts @@ to_tsquery('english', 'backend <-> crushed') "
109+
" WHERE fts @@ "
110+
" to_tsquery('english', 'backend <-> crushed') "
104111
" ORDER BY sent <=| '2016-01-01 00:01' LIMIT 5"
105112
),
106113
b'1999-06-02 11:52:46|Re: [HACKERS] PID of backend\n'
@@ -109,12 +116,13 @@ def test_order_by(self):
109116
self.assertEqual(
110117
self.node.safe_psql(
111118
"pglist",
112-
"SELECT count(*) FROM pglist WHERE fts @@ to_tsquery('english', 'tom & lane')"
119+
"SELECT count(*) FROM pglist "
120+
"WHERE fts @@ to_tsquery('english', 'tom & lane')"
113121
),
114122
b'222813\n'
115123
)
116124
except Exception as e:
117-
self.printlog(self.node.logs_dir + "/postgresql.log")
125+
self.printlog(os.path.join(self.node.logs_dir, "postgresql.log"))
118126
raise e
119127

120128
if __name__ == "__main__":

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy