Skip to content

Commit 0c1e884

Browse files
committed
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
1 parent 8a337b0 commit 0c1e884

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

contrib/auto_explain/.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/auto_explain/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ OBJS = \
66
auto_explain.o
77
PGFILEDESC = "auto_explain - logging facility for execution plans"
88

9+
TAP_TESTS = 1
10+
911
ifdef USE_PGXS
1012
PG_CONFIG = pg_config
1113
PGXS := $(shell $(PG_CONFIG) --pgxs)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 4;
7+
8+
my $node = get_new_node('main');
9+
$node->init;
10+
$node->append_conf('postgresql.conf',
11+
"shared_preload_libraries = 'auto_explain'");
12+
$node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0");
13+
$node->append_conf('postgresql.conf', "auto_explain.log_analyze = on");
14+
$node->start;
15+
16+
# run a couple of queries
17+
$node->safe_psql("postgres", "SELECT * FROM pg_class;");
18+
$node->safe_psql("postgres",
19+
"SELECT * FROM pg_proc WHERE proname = 'int4pl';");
20+
21+
# emit some json too
22+
$node->append_conf('postgresql.conf', "auto_explain.log_format = json");
23+
$node->reload;
24+
$node->safe_psql("postgres", "SELECT * FROM pg_proc;");
25+
$node->safe_psql("postgres",
26+
"SELECT * FROM pg_class WHERE relname = 'pg_class';");
27+
28+
$node->stop('fast');
29+
30+
my $log = $node->logfile();
31+
32+
my $log_contents = slurp_file($log);
33+
34+
like(
35+
$log_contents,
36+
qr/Seq Scan on pg_class/,
37+
"sequential scan logged, text mode");
38+
39+
like(
40+
$log_contents,
41+
qr/Index Scan using pg_proc_proname_args_nsp_index on pg_proc/,
42+
"index scan logged, text mode");
43+
44+
like(
45+
$log_contents,
46+
qr/"Node Type": "Seq Scan"[^}]*"Relation Name": "pg_proc"/s,
47+
"sequential scan logged, json mode");
48+
49+
like(
50+
$log_contents,
51+
qr/"Node Type": "Index Scan"[^}]*"Index Name": "pg_class_relname_nsp_index"/s,
52+
"index scan logged, json mode");

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