21
21
class PglistTests (unittest .TestCase ):
22
22
23
23
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" ))
25
28
try :
26
29
self .node .init ()
27
30
self .node .append_conf ("postgresql.conf" ,
@@ -30,26 +33,20 @@ def setUp(self):
30
33
"max_wal_size='2GB'\n "
31
34
"work_mem='50MB'" )
32
35
self .node .start ()
33
-
34
- self .init_pglist_data (self .node )
35
36
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") )
37
38
raise e
38
39
39
40
def tearDown (self ):
40
41
tg .stop_all ()
41
42
42
43
def init_pglist_data (self , node ):
43
44
# Check if 'pglist' base exists
44
- base_exists = False
45
45
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 :
53
50
return
54
51
55
52
# Check if 'pglist' dump exists
@@ -58,12 +55,12 @@ def init_pglist_data(self, node):
58
55
if not os .path .isfile (pglist_dump ):
59
56
pglist_dumpgz = pglist_dump + ".gz"
60
57
if not os .path .isfile (pglist_dumpgz ):
61
- print ("Downloading: %s" % pglist_dumpgz )
58
+ print ("Downloading: {0}" . format ( pglist_dumpgz ) )
62
59
request .urlretrieve (
63
60
"http://www.sai.msu.su/~megera/postgres/files/pglist-28-04-16.dump.gz" ,
64
61
pglist_dumpgz )
65
62
66
- print ("Decompressing: %s" % pglist_dumpgz )
63
+ print ("Decompressing: {0}" . format ( pglist_dumpgz ) )
67
64
gz = gzip .open (pglist_dumpgz , 'rb' )
68
65
with open (pglist_dump , 'wb' ) as f :
69
66
f .write (gz .read ())
@@ -85,13 +82,22 @@ def printlog(self, logfile):
85
82
def test_order_by (self ):
86
83
"""Tests SELECT constructions to 'pglist' base"""
87
84
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 (
91
87
"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)" )
95
101
96
102
print ("Running tests" )
97
103
@@ -100,7 +106,8 @@ def test_order_by(self):
100
106
"pglist" ,
101
107
"SELECT sent, subject "
102
108
" FROM pglist "
103
- " WHERE fts @@ to_tsquery('english', 'backend <-> crushed') "
109
+ " WHERE fts @@ "
110
+ " to_tsquery('english', 'backend <-> crushed') "
104
111
" ORDER BY sent <=| '2016-01-01 00:01' LIMIT 5"
105
112
),
106
113
b'1999-06-02 11:52:46|Re: [HACKERS] PID of backend\n '
@@ -109,12 +116,13 @@ def test_order_by(self):
109
116
self .assertEqual (
110
117
self .node .safe_psql (
111
118
"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')"
113
121
),
114
122
b'222813\n '
115
123
)
116
124
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") )
118
126
raise e
119
127
120
128
if __name__ == "__main__" :
0 commit comments