Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6edd4b5

Browse files
authored
Merge pull request #136 from postgrespro/PGPRO-11495
Remake of pglist_test.py but on the perl.
2 parents f82ab18 + 2f03e1b commit 6edd4b5

File tree

7 files changed

+230
-171
lines changed

7 files changed

+230
-171
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ REGRESS = security rum rum_validate rum_hash ruminv timestamp orderby orderby_ha
3434

3535
TAP_TESTS = 1
3636

37+
EXTRA_CLEAN = pglist_tmp
38+
3739
ifdef USE_PGXS
3840
PG_CONFIG = pg_config
3941
PGXS := $(shell $(PG_CONFIG) --pgxs)

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ Typical installation procedure may look like this:
6060

6161
> **Important:** Don't forget to set the `PG_CONFIG` variable in case you want to test `RUM` on a custom build of PostgreSQL. Read more [here](https://wiki.postgresql.org/wiki/Building_and_Installing_PostgreSQL_Extension_Modules).
6262
63+
## Tests
64+
65+
$ make check
66+
67+
This command runs:
68+
- regression tests;
69+
- isolation tests;
70+
- tap tests.
71+
72+
One of the tap tests downloads a 1GB archive and then unpacks it
73+
into a file weighing almost 3GB. It is disabled by default.
74+
75+
To run this test, you need to set an environment variable:
76+
77+
$ export PG_TEST_EXTRA=big_values
78+
79+
The way to turn it off again:
80+
81+
$ export -n PG_TEST_EXTRA
82+
6383
## Common operators and functions
6484

6585
The **rum** module provides next operators.

t/002_pglist.pl

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Test RUM index with big base 'pglist'.
2+
use strict;
3+
use warnings;
4+
use Config;
5+
use Test::More;
6+
7+
plan skip_all => 'This test requires downloading a 1GB archive. ' .
8+
'The unpacked file weighs almost 3GB. ' .
9+
'Perform only if the big_values is enabled in PG_TEST_EXTRA'
10+
unless $ENV{PG_TEST_EXTRA} && $ENV{PG_TEST_EXTRA} =~ /\bbig_values\b/;
11+
12+
plan tests => 4;
13+
14+
my $node;
15+
16+
# Utility function
17+
18+
sub file_exists
19+
{
20+
my ($file) = @_;
21+
return -e $file;
22+
}
23+
24+
# Check the existence of the test base, install if necessary
25+
26+
sub install_pglist
27+
{
28+
my $dir = Cwd->getcwd; #current directory
29+
30+
my %config = (
31+
#directory with pglist dump must be inside the current directory
32+
pglist_tmp_dir => $dir . '/pglist_tmp/',
33+
dump_name => 'pglist-28-04-16.dump',
34+
dump_url => 'http://www.sai.msu.su/~megera/postgres/files/pglist-28-04-16.dump.gz',
35+
pglist_archive => $dir . '/pglist_tmp/' . 'pglist-28-04-16.dump.gz',
36+
);
37+
38+
my $path_to_dump = $config{pglist_tmp_dir} . $config{dump_name};
39+
40+
if (file_exists($path_to_dump))
41+
{
42+
note($config{dump_name} . ' already installed');
43+
}
44+
else
45+
{
46+
# Create folder /contrib/rum/pglist_tmp if not already exists
47+
mkdir($config{pglist_tmp_dir}, 0700)
48+
unless file_exists($config{pglist_tmp_dir});
49+
50+
# Download archive pglist-28-04-16.dump.gz if not already exists
51+
unless (file_exists($config{pglist_archive}))
52+
{
53+
note('Downloading pglist dump in ' . $config{pglist_archive});
54+
55+
# Flag "-nv" allows us to avoid frequent messages
56+
# about the download status in the log.
57+
# But it can be enabled for debugging purposes.
58+
system("wget -P $config{pglist_tmp_dir} -nv $config{dump_url}") == 0
59+
or die "Couldn't get archive by link: $?";
60+
}
61+
62+
# Unzip the dump. Delete archive to save memory
63+
system("gzip -d $config{pglist_archive}") == 0
64+
or die "Couldn't extract archive: $?";
65+
66+
file_exists($path_to_dump)
67+
or die "Failed to get " . $config{dump_name};
68+
69+
note($config{dump_name} . ' is ready to use');
70+
}
71+
72+
$node->psql("postgres", "CREATE DATABASE pglist");
73+
$node->psql("postgres", "CREATE ROLE oleg");
74+
my $command = "'" . $path_to_dump . "'";
75+
my $result = $node->psql("pglist", '\i ' . $command);
76+
}
77+
78+
# Tests SELECT constructions to 'pglist' base
79+
80+
sub test_select
81+
{
82+
note("Creating index 'rumidx_orderby_sent'");
83+
84+
$node->safe_psql("pglist", "CREATE INDEX rumidx_orderby_sent ON pglist " .
85+
"USING rum (fts rum_tsvector_timestamp_ops, sent) " .
86+
"WITH (attach=sent, to=fts, order_by_attach=t)");
87+
88+
note("Test ORDER BY timestamp");
89+
90+
my $result1 = $node->safe_psql("pglist",
91+
"SELECT sent, subject FROM pglist WHERE fts @@ " .
92+
"to_tsquery('english', 'backend <-> crushed') " .
93+
"ORDER BY sent <=| '2016-01-01 00:01' LIMIT 5");
94+
95+
is($result1, '1999-06-02 11:52:46|Re: [HACKERS] PID of backend');
96+
97+
note("Test tsvector filter");
98+
99+
my $result2 = $node->safe_psql("pglist",
100+
"SELECT count(*) FROM pglist " .
101+
"WHERE fts @@ to_tsquery('english', 'tom & lane')");
102+
103+
is($result2, '222813');
104+
105+
$node->safe_psql("pglist", "DROP INDEX rumidx_orderby_sent");
106+
}
107+
108+
sub test_order_by
109+
{
110+
note("Creating index 'pglist_rum_idx'");
111+
112+
$node->safe_psql("pglist",
113+
"CREATE INDEX pglist_rum_idx ON pglist " .
114+
"USING rum (fts rum_tsvector_ops)");
115+
116+
note("Test ORDER BY tsvector");
117+
118+
my $result3 = $node->safe_psql("pglist",
119+
"SELECT id FROM pglist " .
120+
"WHERE fts @@ to_tsquery('english', 'postgres:*') " .
121+
"ORDER BY fts <=> " .
122+
"to_tsquery('english', 'postgres:*') LIMIT 9");
123+
124+
is((split(" ", $result3))[0], '816114');
125+
126+
# Autovacuum after large update, with active RUM index crashes postgres
127+
note("Test Issue #19");
128+
129+
my $stderr;
130+
$node->safe_psql("pglist", "DELETE FROM pglist WHERE id < 100000");
131+
$node->safe_psql("pglist", "vacuum", stderr => \$stderr);
132+
133+
is($stderr, undef);
134+
135+
$node->safe_psql("pglist", "DROP INDEX pglist_rum_idx");
136+
}
137+
138+
# Start backend
139+
140+
my $pg_15_modules;
141+
142+
BEGIN
143+
{
144+
$pg_15_modules = eval
145+
{
146+
require PostgreSQL::Test::Cluster;
147+
require PostgreSQL::Test::Utils;
148+
return 1;
149+
};
150+
151+
unless (defined $pg_15_modules)
152+
{
153+
$pg_15_modules = 0;
154+
155+
require PostgresNode;
156+
require TestLib;
157+
}
158+
}
159+
160+
note('PostgreSQL 15 modules are used: ' . ($pg_15_modules ? 'yes' : 'no'));
161+
162+
if ($pg_15_modules)
163+
{
164+
$node = PostgreSQL::Test::Cluster->new("master");
165+
}
166+
else
167+
{
168+
$node = PostgresNode::get_new_node("master");
169+
}
170+
171+
$node->init(allows_streaming => 1);
172+
$node->append_conf("postgresql.conf", "shared_buffers='4GB'\n" .
173+
"maintenance_work_mem='2GB'\n" .
174+
"max_wal_size='2GB'\n" .
175+
"work_mem='50MB'");
176+
$node->start;
177+
178+
# Check the existence of the pglist base
179+
180+
note('Check the existence of the pglist base...');
181+
my $check_pglist = $node->psql('postgres', "SELECT count(*) FROM pg_database " .
182+
"WHERE datistemplate = false AND " .
183+
"datname = 'pglist'");
184+
if ($check_pglist == 1)
185+
{
186+
note("pglist already exists");
187+
}
188+
else
189+
{
190+
note("Create pglist database");
191+
install_pglist();
192+
}
193+
194+
$node->psql("pglist", "CREATE EXTENSION rum");
195+
note('Setup is completed successfully');
196+
197+
eval
198+
{
199+
test_select();
200+
test_order_by();
201+
$node->stop();
202+
done_testing();
203+
1;
204+
} or do {
205+
note('Something went wrong: $@\n');
206+
};
207+

tests/README.md

-14
This file was deleted.

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)