Skip to content

Commit 2865b40

Browse files
committed
Add a regression test for contrib/pg_prewarm.
We had a little bit of coverage here thanks to e2f65f4, but not enough; notably, autoprewarm wasn't exercised at all. Dong Wook Lee, with help from Julien Rouhaud and myself Discussion: https://postgr.es/m/20220629053812.mifmdrch5iuasg2s@home-desktop
1 parent 3592e0f commit 2865b40

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

contrib/pg_prewarm/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

contrib/pg_prewarm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ EXTENSION = pg_prewarm
1010
DATA = pg_prewarm--1.1--1.2.sql pg_prewarm--1.1.sql pg_prewarm--1.0--1.1.sql
1111
PGFILEDESC = "pg_prewarm - preload relation data into system buffer cache"
1212

13+
TAP_TESTS = 1
14+
1315
ifdef USE_PGXS
1416
PG_CONFIG = pg_config
1517
PGXS := $(shell $(PG_CONFIG) --pgxs)

contrib/pg_prewarm/t/001_basic.pl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
# Copyright (c) 2021-2022, PostgreSQL Global Development Group
3+
4+
use strict;
5+
use warnings;
6+
7+
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
9+
use Test::More;
10+
11+
12+
my $node = PostgreSQL::Test::Cluster->new('main');
13+
14+
$node->init;
15+
$node->append_conf(
16+
'postgresql.conf',
17+
qq{shared_preload_libraries = 'pg_prewarm'
18+
pg_prewarm.autoprewarm = true
19+
pg_prewarm.autoprewarm_interval = 0});
20+
$node->start;
21+
22+
# setup
23+
$node->safe_psql("postgres",
24+
"CREATE EXTENSION pg_prewarm;\n"
25+
. "CREATE TABLE test(c1 int);\n"
26+
. "INSERT INTO test SELECT generate_series(1, 100);");
27+
28+
# test read mode
29+
my $result =
30+
$node->safe_psql("postgres", "SELECT pg_prewarm('test', 'read');");
31+
like($result, qr/^[1-9][0-9]*$/, 'read mode succeeded');
32+
33+
# test buffer_mode
34+
$result =
35+
$node->safe_psql("postgres", "SELECT pg_prewarm('test', 'buffer');");
36+
like($result, qr/^[1-9][0-9]*$/, 'buffer mode succeeded');
37+
38+
# prefetch mode might or might not be available
39+
my ($cmdret, $stdout, $stderr) =
40+
$node->psql("postgres", "SELECT pg_prewarm('test', 'prefetch');");
41+
ok( ( $stdout =~ qr/^[1-9][0-9]*$/
42+
or $stderr =~ qr/prefetch is not supported by this build/),
43+
'prefetch mode succeeded');
44+
45+
# test autoprewarm_dump_now()
46+
$result = $node->safe_psql("postgres", "SELECT autoprewarm_dump_now();");
47+
like($result, qr/^[1-9][0-9]*$/, 'autoprewarm_dump_now succeeded');
48+
49+
# restart, to verify that auto prewarm actually works
50+
$node->restart;
51+
52+
$node->wait_for_log(
53+
"autoprewarm successfully prewarmed [1-9][0-9]* of [0-9]+ previously-loaded blocks"
54+
);
55+
56+
$node->stop;
57+
58+
done_testing();

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