From 52a77a5250f765c79ccda3af00906505c0163141 Mon Sep 17 00:00:00 2001 From: Alexey Kondratov Date: Mon, 9 Nov 2020 19:04:10 +0300 Subject: [PATCH v2 1/4] pg_prewarm: add tap test for autoprewarm feature --- contrib/pg_prewarm/Makefile | 2 + contrib/pg_prewarm/t/001_autoprewarm.pl | 59 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 contrib/pg_prewarm/t/001_autoprewarm.pl diff --git a/contrib/pg_prewarm/Makefile b/contrib/pg_prewarm/Makefile index b13ac3c813..9cfde8c4e4 100644 --- a/contrib/pg_prewarm/Makefile +++ b/contrib/pg_prewarm/Makefile @@ -10,6 +10,8 @@ EXTENSION = pg_prewarm DATA = pg_prewarm--1.1--1.2.sql pg_prewarm--1.1.sql pg_prewarm--1.0--1.1.sql PGFILEDESC = "pg_prewarm - preload relation data into system buffer cache" +TAP_TESTS = 1 + ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/contrib/pg_prewarm/t/001_autoprewarm.pl b/contrib/pg_prewarm/t/001_autoprewarm.pl new file mode 100644 index 0000000000..744c443169 --- /dev/null +++ b/contrib/pg_prewarm/t/001_autoprewarm.pl @@ -0,0 +1,59 @@ +# +# Check that pg_prewarm can dump blocks from shared buffers +# to PGDATA/autoprewarm.blocks. +# + +use strict; +use Test::More; +use TestLib; +use Time::HiRes qw(usleep); +use warnings; + +use PostgresNode; + +plan tests => 3; + +# Wait up to 180s for pg_prewarm to dump blocks. +sub wait_for_dump +{ + my $path = shift; + + foreach my $i (0 .. 1800) + { + last if -e $path; + usleep(100_000); + } +} + +my $node = get_new_node("node"); +$node->init; +$node->append_conf( + 'postgresql.conf', qq( +shared_preload_libraries = 'pg_prewarm' +pg_prewarm.autoprewarm = 'on' +pg_prewarm.autoprewarm_interval = 1 +)); +$node->start; + +my $blocks_path = $node->data_dir . '/autoprewarm.blocks'; + +# Check that we can dump blocks on timeout. +wait_for_dump($blocks_path); +ok(-e $blocks_path, 'file autoprewarm.blocks should be present in the PGDATA'); + +# Check that we can dump blocks on shutdown. +$node->stop; +$node->append_conf( + 'postgresql.conf', qq( +pg_prewarm.autoprewarm_interval = 0 +)); + +# Remove autoprewarm.blocks +unlink($blocks_path) || die "$blocks_path: $!"; +ok(!-e $blocks_path, 'sanity check, dump on timeout is turned off'); + +$node->start; +$node->stop; + +wait_for_dump($blocks_path); +ok(-e $blocks_path, 'file autoprewarm.blocks should be present in the PGDATA after clean shutdown'); base-commit: 8f113698b63b15a4e0a4b15d3ee37238c1d1821d -- 2.19.1