commit 4ff17c7f2008f7e6716d10832571f3302b4e91e6
Author: Ian Barwick <ian@2ndquadrant.com>
Date:   Tue Jul 16 17:45:39 2019 +0900

    Add TAP test for configuration file inclusion tracking

diff --git a/src/test/configuration/t/002_track_included_files.pl b/src/test/configuration/t/002_track_included_files.pl
new file mode 100644
index 0000000000..3450c4c0ae
--- /dev/null
+++ b/src/test/configuration/t/002_track_included_files.pl
@@ -0,0 +1,113 @@
+# Test that a configuration file is not read more than once
+
+use strict;
+use warnings;
+use PostgresNode;
+use TestLib;
+use Test::More tests => 5;
+
+our $postgresql_conf = 'postgresql.conf';
+our $include_first_conf = 'aaa.conf';
+
+our ($expected, $result, $config_line);
+
+# Initialize a single node
+# ------------------------
+
+my $node = get_new_node('primary');
+$node->init();
+$node->start;
+
+# Get number of lines in current postgresql.conf
+my $conf = $node->read_conf($postgresql_conf);
+my @conf = split("\n", $conf);
+my $conf_lines = scalar @conf;
+
+# Attempt to have the main postgresql.conf file include itself
+
+my $include = <<'EO_CONF';
+include = 'postgresql.conf'
+include = './postgresql.conf'
+include_if_exists = 'postgresql.conf'
+include_if_exists = './postgresql.conf'
+include_dir = '.'
+EO_CONF
+
+$node->append_conf($postgresql_conf, $include);
+
+$expected = sprintf(
+	'configuration file "%s/%s" was previously parsed',
+	$node->data_dir,
+	$postgresql_conf,
+);
+
+# 1. Check "include" directive (filename only)
+# --------------------------------------------
+
+$config_line = $conf_lines + 1;
+
+$result = $node->safe_psql('postgres',
+						   "SELECT error FROM pg_catalog.pg_file_settings WHERE sourceline = $config_line");
+
+is($result,
+   $expected,
+   'Check "include" directive (filename only)');
+
+# 2. Check "include" directive (filename with relative path)
+# ----------------------------------------------------------
+
+$config_line = $conf_lines + 2;
+
+$result = $node->safe_psql('postgres',
+						   "SELECT error FROM pg_catalog.pg_file_settings WHERE sourceline = $config_line");
+
+is($result,
+   $expected,
+   'Check "include" directive (filename with relative path)');
+
+
+# 3. Check "include_if_exists" directive (filename only)
+# ------------------------------------------------------
+
+$config_line = $conf_lines + 3;
+
+$result = $node->safe_psql('postgres',
+						   "SELECT error FROM pg_catalog.pg_file_settings WHERE sourceline = $config_line");
+
+is($result,
+   $expected,
+   'Check "include_if_exists" directive (filename only)');
+
+
+
+# 4. Check "include_if_exists" directive (filename with relative path)
+# --------------------------------------------------------------------
+
+$config_line = $conf_lines + 4;
+
+$result = $node->safe_psql('postgres',
+						   "SELECT error FROM pg_catalog.pg_file_settings WHERE sourceline = $config_line");
+
+is($result,
+   $expected,
+   'Check "include_if_exists" directive (filename with relative path)');
+
+
+# 5. Check "include_dir" directive
+# --------------------------------
+
+# Create a configuration file which will be read first
+# by "include_dir"
+$node->append_conf($include_first_conf, "include = 'postgresql.conf'\n");
+$node->append_conf($postgresql_conf, "include_dir = '.'\n");
+
+$result = $node->safe_psql('postgres',
+						   "SELECT error FROM pg_catalog.pg_file_settings ".
+						   " WHERE sourcefile LIKE '%$include_first_conf' ".
+						   "   AND sourceline = 1");
+is($result,
+   $expected,
+   'Check "include_dir" directive');
+
+
+
