mirror of https://github.com/postgres/postgres
Add a simple test for contrib/auto_explain.
This module formerly had zero test coverage. Discussion: https://postgr.es/m/1445881.1611441692@sss.pgh.pa.us
This commit is contained in:
parent
8a337b0ed2
commit
0c1e8845f2
|
@ -0,0 +1,4 @@
|
|||
# Generated subdirectories
|
||||
/log/
|
||||
/results/
|
||||
/tmp_check/
|
|
@ -6,6 +6,8 @@ OBJS = \
|
|||
auto_explain.o
|
||||
PGFILEDESC = "auto_explain - logging facility for execution plans"
|
||||
|
||||
TAP_TESTS = 1
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use PostgresNode;
|
||||
use TestLib;
|
||||
use Test::More tests => 4;
|
||||
|
||||
my $node = get_new_node('main');
|
||||
$node->init;
|
||||
$node->append_conf('postgresql.conf',
|
||||
"shared_preload_libraries = 'auto_explain'");
|
||||
$node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0");
|
||||
$node->append_conf('postgresql.conf', "auto_explain.log_analyze = on");
|
||||
$node->start;
|
||||
|
||||
# run a couple of queries
|
||||
$node->safe_psql("postgres", "SELECT * FROM pg_class;");
|
||||
$node->safe_psql("postgres",
|
||||
"SELECT * FROM pg_proc WHERE proname = 'int4pl';");
|
||||
|
||||
# emit some json too
|
||||
$node->append_conf('postgresql.conf', "auto_explain.log_format = json");
|
||||
$node->reload;
|
||||
$node->safe_psql("postgres", "SELECT * FROM pg_proc;");
|
||||
$node->safe_psql("postgres",
|
||||
"SELECT * FROM pg_class WHERE relname = 'pg_class';");
|
||||
|
||||
$node->stop('fast');
|
||||
|
||||
my $log = $node->logfile();
|
||||
|
||||
my $log_contents = slurp_file($log);
|
||||
|
||||
like(
|
||||
$log_contents,
|
||||
qr/Seq Scan on pg_class/,
|
||||
"sequential scan logged, text mode");
|
||||
|
||||
like(
|
||||
$log_contents,
|
||||
qr/Index Scan using pg_proc_proname_args_nsp_index on pg_proc/,
|
||||
"index scan logged, text mode");
|
||||
|
||||
like(
|
||||
$log_contents,
|
||||
qr/"Node Type": "Seq Scan"[^}]*"Relation Name": "pg_proc"/s,
|
||||
"sequential scan logged, json mode");
|
||||
|
||||
like(
|
||||
$log_contents,
|
||||
qr/"Node Type": "Index Scan"[^}]*"Index Name": "pg_class_relname_nsp_index"/s,
|
||||
"index scan logged, json mode");
|
Loading…
Reference in New Issue